inplace_swap_column#
- sklearn.utils.sparsefuncs.inplace_swap_column(X, m, n)[Quelle]#
Tauscht zwei Spalten einer CSC/CSR-Matrix in-place.
- Parameter:
- Xspärliche Matrix der Form (n_samples, n_features)
Matrix, deren zwei Spalten vertauscht werden sollen. Sie sollte im CSR- oder CSC-Format vorliegen.
- mint
Index der zu vertauschenden Spalte von X.
- nint
Index der zu vertauschenden Spalte von X.
Beispiele
>>> 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_column(csr, 0, 1) >>> csr.todense() matrix([[0, 8, 2], [0, 0, 5], [0, 0, 0], [0, 0, 0]])