inplace_swap_row#

sklearn.utils.sparsefuncs.inplace_swap_row(X, m, n)[源]#

原地交换 CSC/CSR 矩阵的两行。

参数:
X形状为 (n_samples, n_features) 的稀疏矩阵

要交换行的矩阵。它应该是 CSR 或 CSC 格式。

m整型

X 中要交换的行的索引。

n整型

X 中要交换的行的索引。

示例

>>> from sklearn.utils import sparsefuncs
>>> from scipy import sparse
>>> import numpy as np
>>> indptr = np.array([0, 2, 3, 3, 3])
>>> indices = np.array([0, 2, 2])
>>> data = np.array([8, 2, 5])
>>> csr = sparse.csr_matrix((data, indices, indptr))
>>> csr.todense()
matrix([[8, 0, 2],
        [0, 0, 5],
        [0, 0, 0],
        [0, 0, 0]])
>>> sparsefuncs.inplace_swap_row(csr, 0, 1)
>>> csr.todense()
matrix([[0, 0, 5],
        [8, 0, 2],
        [0, 0, 0],
        [0, 0, 0]])