[SciPy-user] sparse matrix formats

Travis Oliphant oliphant at ee.byu.edu
Tue Oct 26 17:25:53 CDT 2004


David Grant wrote:

> I am a bit boggled by all these sparse matrix types in the sparse class.
>
> Can anyone recommend which are the standard one I should use (when in 
> doubt)?

spmatrix is just the base class and is not functional by itself:

The formats at the top are currently best supported. 

csc_matrix  --- used internally by lot's of routines, best for numerics 
but can be slow to construct using Python indexing
csr_matrix  ---  nearly as fast as csc_matrix and useful for fast 
transpose operations.
dok_matrix --- fast construction in Python (just a simple dictionary), 
but must be converted to csc_matrix for fast matrix multiplication, etc.

I hope this helps,

The documentation is lacking for Sparse, but the code should be fairly 
readable.  Just ignore all but csc_matrix, csr_matrix, and dok_matrix  
for now.

There are some bugs in dok_matrix  and in mixed csc csr matrix 
multiplication in SciPy 0.3.2 that have been fixed in CVS.

-Travis



More information about the SciPy-user mailing list