[SciPy-User] how to get indices

Gael Varoquaux gael.varoquaux@normalesup....
Mon Sep 13 03:28:16 CDT 2010


On Mon, Sep 13, 2010 at 10:16:33AM +0200, Marcel Blattner wrote:
>    I have a small problem. I have for example a csc_matrix A. I want to find
>    indices of values bigger then a treshold.
>    In numpy I simply can do: a,b = A > threshold...is there something similar
>    in Scipy?

The difficulty here is that you are dealing with sparse matrices, for
which access to data is not as simple. I believe the easiest option is to
convert your matrix to coo, and operate directly on the row/col/data
arrays:

a = a.tocoo()
mask = a.data > threshold
col = a.col[mask]
row = a.row[mask]

HTH,

Gaël


More information about the SciPy-User mailing list