[SciPy-user] broadcasting elementwise on sparse matrix
Wed Oct 1 10:52:32 CDT 2008
On Wed, Oct 1, 2008 at 9:50 AM, Robin <firstname.lastname@example.org> wrote:
> Is there any way to get broadcasted element wise operations on sparse matrices?
> I would like to do something like A * x if A was (n,n) array and x was
> a (n,) array. I saw the sparse matrices have a .multiply method, but
> it doesn't seem to broadcast in the same way as the standard
> multiplication, ie As.multiply(x) gives an "inconsistent shapes"
> The best I have is As.multiply(tile(x,(n,1))) although this has the memory
> overhead that is normally avoided with broadcasting. Is there an alternative?
That particular operation is just scaling of the columns, right? If
so, you can use:
>>> As * spdiags([x],, n,n,)
If As is already a CSR matrix, then you can cheat a little and do the
operation in place:
>>> As.data *= x[As.indices]
Nathan Bell email@example.com
More information about the SciPy-user