[SciPy-dev] Scipy equivalents of MATLAB's sparse/find/accumarray

Viral Shah vshah@interactivesupercomputing....
Mon Apr 7 13:53:11 CDT 2008

Nathan, thanks for your earlier response on sparse matrix indexing.

The other thing that I found cumbersome with the current sparse  
implementation in scipy is not being able to figure out the exact  
equivalents of Matlab's sparse/accumarray and find. In the following  
examples, I will denote Matlab codes with M>> and Python with P>>

M>> S = sparse (I, J, V, m, n)

The equivalent in Python seems to be:
P>> S = sparse.csc_matrix ((obj, ij), dims)
P>> S = sparse.csr_matrix ((obj, ij), dims)

It wasn't clear looking at the documentation, what happens when there  
are duplicate row/col values. Matlab's sparse() adds duplicates, and  
accumarray() provides a more general way to combine duplicates. I was  
wondering, if it would be possible to add an extra argument that would  
allow the user to specify what to do with duplicates. Options could be  
last, any, sum, prod, max, min, argmax, argmin, or a user specified  

M>> F = find (a)

The equivalent seems to be;
P>> f = where(a)

But where doesn't seem to work for sparse matrices, in 0.6.


More information about the Scipy-dev mailing list