nonzero
scipy.sparse.dok_matrix.
- dok_matrix.nonzero()
Nonzero indices of the array/matrix.
- Returns:
- row : ndarray
Row indices of non-zero elements.
- col : ndarray
Column indices of non-zero elements.
Examples
Nonzero indices of the array/matrix.
Row indices of non-zero elements.
Column indices of non-zero elements.
>>> from scipy.sparse import csr_array
>>> A = csr_array([[1, 2, 0], [0, 0, 3], [4, 0, 5]])
>>> A.nonzero()
(array([0, 0, 1, 2, 2], dtype=int32), array([0, 1, 2, 0, 2], dtype=int32))