[SciPy-user] fastest way to populate sparse matrix?

Nathan Bell wnbell@gmail....
Wed Dec 10 12:46:38 CST 2008


On Wed, Dec 10, 2008 at 12:54 PM, Peter Skomoroch
<peter.skomoroch@gmail.com> wrote:
> What is the fastest way to replace non-zero elements of a sparse
> matrix with corresponding elements from a product of dense matrices,
> without the memory overhead of computing the entire dense matrix
> product?
>
> The code below demonstrates the way I am doing it now: looping through
> the nonzero elements in the sparse matrix, and forming the
> corresponding row - column product from the dense matrices.  It uses
> the sparse module from the latest scipy trunk.
>

The fastest way to construct a sparse matrix is using the COO format
as discussed here:
http://www.scipy.org/SciPyPackages/Sparse#head-be8a0be5d0e44c4d59550d64fb0173508073c36e

Using COO instead of LIL should be considerably faster.

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


More information about the SciPy-user mailing list