I was thinking about using coo_matrix.nonzero() , which returns a tuple of two arrays containing indices of nonzero entries in a given matrix. In the example from the documents it is indicated:
>>> from scipy.sparse import coo_matrix >>> A = coo_matrix([[1,2,0],[0,0,3],[4,0,5]]) >>> nonzero_entrys = A.nonzero() (array([0, 0, 1, 2, 2]), array([0, 1, 2, 0, 2]))
Then I would do something like len(nonzero_entrys[0]) , but it looks like a leak. Is there a better way that I forgot in the docs?
source share