inplace_csr_row_normalize_l2#

sklearn.utils.sparsefuncs_fast.inplace_csr_row_normalize_l2(X)#

就地规范化CSR矩阵或数组的行,使其L2范数为1。

Parameters:
Xscipy.sparse.csr_matrix, shape=(n_samples, n_features)

输入矩阵或数组,将就地修改。

Examples

>>> from scipy.sparse import csr_matrix
>>> from sklearn.utils.sparsefuncs_fast import inplace_csr_row_normalize_l2
>>> X = csr_matrix(([1.0, 2.0, 3.0], [0, 2, 3], [0, 3, 4]), shape=(3, 4))
>>> X.toarray()
array([[1., 2., 0., 0.],
       [0., 0., 3., 0.],
       [0., 0., 0., 4.]])
>>> inplace_csr_row_normalize_l2(X)
>>> X.toarray()
array([[0.44...   , 0.89...   , 0.        , 0.        ],
       [0.        , 0.        , 1.        , 0.        ],
       [0.        , 0.        , 0.        , 1.        ]])