[SciPy-User] Help on matrix multiplication with spare result

Ningping Wang wangnp.daniel at gmail.com
Tue May 12 14:33:19 EDT 2015


I have two dense matrices U (10000x50) and V(50x10000), and one sparse
matrix A(10000x10000). Each element in A is either 1 or 0 and only 1%
elements are non-zero. I hope to find A*(UV) and I write A*(U.dot(V) in
SciPy, noting that '*' is element-wise multiplication. Here SciPy will
calculate a dense matrix UV first, then filter the result using A. But UV
is dense and large (10000x10000) so it's very slow.

Because I only need a few elements of UV indicated by A, it should save a
lot of time if only necessary elements are calculated. Is there a way to
instruct scipy to do this?

BTW, I used Matlab to solve this problem before and Matlab is smart enough
to find what I'm trying to do and works efficiently. In Matlab I write like
this: A.*(U*V).

Thanks,
Daniel
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.scipy.org/pipermail/scipy-user/attachments/20150513/11936ca1/attachment.html>


More information about the SciPy-User mailing list