2017-10-18 12 views

Répondre

0

code:

from scipy.sparse import find, csr_matrix 
import numpy as np 

A = csr_matrix(np.array([[0, 0, 0, 0, 0, 1], [0, 0, 0, 0, 0, 0], [1, 1, 0, 0, 0, 0]])) 
print(A.todense()) 

nnz_per_row = A.getnnz(axis=1) 
result = np.where(nnz_per_row > 0)[0] 

print(result) 

sortie:

[[0 0 0 0 0 1] 
[0 0 0 0 0 0] 
[1 1 0 0 0 0]] 
[0 2]