原地CSR矩阵行L1范数归一化#
- sklearn.utils.sparsefuncs_fast.inplace_csr_row_normalize_l1(X)#
原地按其L1范数归一化CSR矩阵或数组的行。
- 参数:
- Xscipy.sparse.csr_matrix 和 scipy.sparse.csr_array, 形状=(n_samples, n_features)
需要就地修改的输入矩阵或数组。
示例
>>> from scipy.sparse import csr_matrix >>> from sklearn.utils.sparsefuncs_fast import inplace_csr_row_normalize_l1 >>> import numpy as np >>> indptr = np.array([0, 2, 3, 4]) >>> indices = np.array([0, 1, 2, 3]) >>> data = np.array([1.0, 2.0, 3.0, 4.0]) >>> X = csr_matrix((data, indices, indptr), shape=(3, 4)) >>> X.toarray() array([[1., 2., 0., 0.], [0., 0., 3., 0.], [0., 0., 0., 4.]]) >>> inplace_csr_row_normalize_l1(X) >>> X.toarray() array([[0.33... , 0.66... , 0. , 0. ], [0. , 0. , 1. , 0. ], [0. , 0. , 0. , 1. ]])