[SciPy-user] Sparse with fast element-wise multiply?

lorenzo bolla lbolla@gmail....
Sun Dec 16 13:03:49 CST 2007


converting the matrix from lil_matrix to csc or csr format gives a 140x
speed improvement on multiplication.

In [4]: A = scipy.sparse.lil_matrix((1000, 1000))

In [5]: A[:,100] = scipy.rand(1000)

In [6]: A[99, :] = scipy.rand(1000)

In [7]: A.setdiag(scipy.rand(1000))

In [8]: %timeit A * A
10 loops, best of 3: 72.2 ms per loop

In [9]: B = A.tocsr()

In [10]: %timeit B * B
1000 loops, best of 3: 510 µs per loop

In [11]: C = A.tocsc()

In [12]: %timeit C * C
1000 loops, best of 3: 527 µs per loop

hth,
L.





On Dec 15, 2007 1:12 AM, David Warde-Farley <dwf@cs.toronto.edu> wrote:

> Hi folks,
>
> I'm currently using sparse.lil_matrix to do element-wise
> multiplication of two sparse matrices, and, well, it's really slow.
> Any suggestions for something speedier? (it seems csr and csc matrices
> don't have .multiply()).
>
> David
>
>
> _______________________________________________
> SciPy-user mailing list
> SciPy-user@scipy.org
> http://projects.scipy.org/mailman/listinfo/scipy-user
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://projects.scipy.org/pipermail/scipy-user/attachments/20071216/570c2b6f/attachment.html 


More information about the SciPy-user mailing list