[SciPy-user] Converting dense into sparse matrices is slow
cimrman3 at ntc.zcu.cz
Mon Mar 20 05:39:57 CST 2006
Nils Wagner wrote:
> Hi all,
> AFAIK linalg.kron only works with dense matrices.
> It would be nice if kron can handle sparse matrices as well.
> The example (bao.py) takes a lot of time
> Kronecker product (sec): 6.28
> Dense to sparse (sec): 70.09
> Number of nonzero elements 16129
> If one uses a dense matrix there are 16777216 entries.
> Anyway, is it possible to accelerate some operations (especially
> csr_matrix()) in bao.py ?
the actual conversion is done by *fulltocsc() function of sparsetools,
which IMHO allocates space for the whole dense matrix which is very
large in your case. Maybe a two-pass approach would be faster - 1. count
the actual nonzeros, 2. build the matrix. I cannot try it right now,
More information about the SciPy-user