[SciPy-User] flattened index for Sparse Matrix?

Lutz Maibaum lutz.maibaum at gmail.com
Wed Nov 3 15:32:34 EDT 2010


On Wed, Nov 3, 2010 at 12:12 PM, LittleBigBrain <braingateway at gmail.com> wrote:
> I am trying sparse matrix these days. I am wondering is there any way
> I can access the sparse matrix with flattened index?

> And is there any more delicate way to obtain max, min of a sparse
> matrix than a[a.nonzero()].max()?

It probably depends on which sparse matrix type you are using. For a
CSR matrix, for example, the data member contains the values of all
non-zero elements. You could do something like a.data.max(), but you
will still have to compare the result to 0 unless the matrix is in
fact dense.

Hope this helps,

  Lutz



More information about the SciPy-User mailing list