[SciPy-User] scipy.sparse.csr_matrix: Refills with same graph, different values

Robert Cimrman cimrman3@ntc.zcu...
Tue Oct 12 03:22:32 CDT 2010


Hi Nico,

On Tue, 12 Oct 2010, Nico Schlömer wrote:

> Hi all,
>
> I do computations with a sparse matrix the values of which need to
> change, but never the sparsity structure.
> Until now, every time the values change, I tossed away the old matrix,
> create a new lil_matrix, and then use .tocsr() to get what I want.
> This seems really wasteful, though, as this way, all the sparsity
> information is computed anew.
> I've tried setting the values in the csr_matrix -- one created --
> directly, but even though they go into spots where there's a nonzero
> already, this operation seems slow. Also, I don't know of a way to
> zero-out a csr_matrix while keeping the sparsity information.
>
> Any hints on this?

The csr_matrix has a data attribute, so zeroing is easy:

mtx.data[:] = 0.0

But then do not perform operations that would create a new matrix, as the 
zero entries would be thrown away.

As for the speed issues, can you be more specific?

r.


More information about the SciPy-User mailing list