[SciPy-User] how to get the indexes of non zero rows of sparse matric efficiently when using scipy?

szebi szebi at gmx.at
Wed Sep 18 14:12:46 EDT 2013


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 at scipy.org
> http://mail.scipy.org/mailman/listinfo/scipy-user


-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 555 bytes
Desc: OpenPGP digital signature
URL: <http://mail.scipy.org/pipermail/scipy-user/attachments/20130918/327aaa06/attachment.sig>


More information about the SciPy-User mailing list