def length_normalize(matrix):
    'Length normalize the matrix\n\n    Args:\n        matrix (np.ndarray): Input matrix that needs to be normalized\n\n    Returns:\n        Normalized matrix\n    '
    norms = np.sqrt(np.sum((matrix ** 2), axis=1))
    norms[(norms == 0)] = 1
    return (matrix / norms[:, np.newaxis])
Length normalize the matrix

Args:
    matrix (np.ndarray): Input matrix that needs to be normalized

Returns:
    Normalized matrix
def length_normalize(matrix):
    'Length normalize the matrix\n\n    Args:\n        matrix (np.ndarray): Input matrix that needs to be normalized\n\n    Returns:\n        Normalized matrix\n    '
    norms = np.sqrt(np.sum((matrix ** 2), axis=1))
    norms[(norms == 0)] = 1
    return (matrix / norms[:, np.newaxis])