📜  规范化矩阵 numpy 中的行 - Python 代码示例

📅  最后修改于: 2022-03-11 14:46:00.533000             🧑  作者: Mango

代码示例1
def normalize_rows(x: numpy.ndarray):
    """
    function that normalizes each row of the matrix x to have unit length.

    Args:
     ``x``: A numpy matrix of shape (n, m)

    Returns:
     ``x``: The normalized (by row) numpy matrix.
    """
    return x/numpy.linalg.norm(x, ord=2, axis=1, keepdims=True)