[SciPy-user] sparse behaviour?

Robert Cimrman cimrman3 at ntc.zcu.cz
Tue Oct 10 05:06:09 CDT 2006

koara at atlas.cz wrote:
>> -----Puvodni zprava----- Od: Stefan van der Walt
>> [mailto:stefan at sun.ac.za] Odesláno: 9. ríjna 2006 23:48 Komu:
>> scipy-user at scipy.org Predmet: Re: [SciPy-user] sparse behaviour? 
>> ... Currently, scipy.cov calls numpy.cov, which knows nothing about
>> sparse matrices.  I don't think there is any reason why it can't be
>> done, it's just that no one has taken the time to implement it.
> Thank you Stefan!
> So indeed my assumption was wrong. Is there a user-friendly list of
> which things work the same for both dense/sparse matrices without any
> additional code, so that i do not re-invent the wheel? Since indexing
> syntax is the same, I imagine some things might work even with a
> simple call to numpy, no?  Just like i assumed cov() would... :>

The short answer (and current status) is:
1. all functions in scipy.sparse and scipy.linsolve work with sparse
matrices and expect sparse matrices (they were written for them)
2. all other functions do not understand sparse matrices.

IMHO the problem here is that the sparse matrix class is not a subclass
of numpy.ndarray. So far, asarray and friends - when used on a sparse
matrix - make an object array with one item - the sparse matrix object.
I would prefer this behaviour changed to:
a) raise exception
b) call .todense() method of the sparse matrix
- here I am more for a) since using a dense-array algorithm on a sparse
matrix will not work well - b) would cause many out-of-memory errors.

And then, of course, sparse matrix algorithms should be continuously
added to reflect the dense ones. (Here, for example, the CSparse library
could help, if wrapped properly to Python.)


More information about the SciPy-user mailing list