I have a sparse matrix:
from scipy.sparse import csr_matrix M=csr_matrix((5,5)) M[2,3]=4 I would like to iterate all non-zero entries, something like:
for x,y,v in M.non_zero_entries: do_something() I try to comprehend the values of M.data,M.indices and M.indptr
Now, in the example above:
print (M.data) #outputs [4] print (M.indices) #outputs [3] print (M.indptr) #outputs [0,0,0,1,1,1] How can I extract the non-zero records from that ?