[SciPy-user] Left hand sparse matrix multiplication

Nathan Bell wnbell at gmail.com
Wed Oct 8 15:28:05 EDT 2008


On Wed, Oct 8, 2008 at 11:41 AM, James Philbin <philbinj at gmail.com> wrote:
>
> I'm trying to compute x*A where x is a dense row vector and A is a
> sparse CSC matrix. A.rmatvec seems to do what I want but is wasteful
> as it computes:
> self.transpose().matvec( other )
> i.e. it computes A^T * x^T.
>
> It seems there should be a much more efficient overload for csc's
> rmatvec which doesn't involve computing the transpose. I hope i'm
> understanding things correctly.
>

CSR.T and CSC.T are constant time operations, they just return the
matrix in the "opposite" format.

In your case, A.T is equivalent to
csr_matrix((A.data,A.indices,A.indptr),
shape=(A.shape[1],A.shape[0])), which simply reinterprets the CSC
format of A as the CSR format of A.T.

This does not hold for other sparse formats so there *is* some room
for improvement.

-- 
Nathan Bell wnbell at gmail.com
http://graphics.cs.uiuc.edu/~wnbell/



More information about the SciPy-User mailing list