how to get the indexes of non zero rows of sparse matric efficiently when using scipy?
for example, a 500x1000 sparse matrix with 300 non zero rows and 5000 non zero items, what i want is the index for the 300 rows, not the index for 5000 items, how to do this efficiently, seems scipy haven't provicde such kind of API ...
Hi, That depends on which matrix you are using. CSC: >>> A = np.arange(100).reshape(10,10) >>> A[[3,7]] = 0 >>> B = scipy.sparse.csc_matrix(A) >>> np.diff(B.indptr).nonzero()[0] CSR: >>> A = np.arange(100).reshape(10,10) >>> A[:,[3,7]] = 0 >>> B = scipy.sparse.csr_matrix(A) >>> np.unique(B.indices) Have Fun! Sebastian On 08/17/2013 05:26 AM, teccy wrote:
for example, a 500x1000 sparse matrix with 300 non zero rows and 5000 non zero items, what i want is the index for the 300 rows, not the index for 5000 items, how to do this efficiently, seems scipy haven't provicde such kind of API ...
_______________________________________________ SciPy-User mailing list SciPy-User@scipy.org http://mail.scipy.org/mailman/listinfo/scipy-user
participants (2)
-
szebi -
teccy