# [SciPy-user] Interaction of sparse and dense matrices in scipy

Nils Wagner nwagner at mecha.uni-stuttgart.de
Tue Feb 21 02:48:29 CST 2006

```Ed Schofield wrote:
>Nils Wagner wrote:
>
>
>>I need some advice on operations between dense and sparse matrix "objects".
>>Which operations are possible in scipy ?
>>
>><snip>
>>
>>- multiplication of a sparse matrix A with a dense matrix C
>>- Kronecker product of sparse matrices ?
>>- Kronecker product of a dense and a sparse matrix ?
>>- sparse matrix functions expm(A),... ?
>>- sparse eigensolver
>>
>>
>>
>I don't know about all of these, but currently multiplication works
>between arrays by sparse matrices (and should be efficient) and you can
>achieve exponentiation for integer powers by repeated multiplication.
>But currently multiplication a * b does NOT work if 'a' is a dense
>*matrix* and 'b' is sparse.  I'd like to fix this, but it's not easy,
>and we'd need to discuss how.
>
>
>>Can I use different sparse formats like csc and csr w.r.t. to
>>
>>
>>
>Yes, it should work for any two formats, but one matrix will usually be
>converted internally to the same format as the other, so it's more
>efficient to use the same format unless you know what you're doing.
>
>
>>And what is the output of A = io.mmread("A.mtx") ? I mean sparse or dense.
>>
>>
>>
>It should be the same format that it was stored in.
>
>-- Ed
>
>_______________________________________________
>SciPy-user mailing list
>SciPy-user at scipy.net
>http://www.scipy.net/mailman/listinfo/scipy-user
>

Hi Ed,

The multiplication a*b, where a is dense a b is sparse, is certainly of
importance.
For example Block Krylov methods make heavily use of such products.
Anyway, it would be nice if scipy can handle such products :-)

Cheers,
Nils

Some References

http://math.nist.gov/spblas/

Maybe we can benift from octave in some sense.

http://octave.sourceforge.net/index/f/krylov.html

Sparse Kronecker product
http://octave.sourceforge.net/index/f/spkron.html

Sparse random matrices
http://octave.sourceforge.net/index/f/sprand.html

.

```