[SciPy-user] sparse+slice? (and hello!)

Ed Schofield schofield at ftw.at
Fri May 19 04:37:34 EDT 2006


On 17/05/2006, at 5:12 PM, Bram de Jong - MTG wrote:

> Ed Schofield wrote:
>>> Perhaps slicing along the non-native axes could be supported as  
>>> well,
>>> even if it's really slow... A simple docstring with a message  
>>> about the
>>> speed would solve the problem, while supplying the user with a "full
>>> set". For small matrices or really sparse ones it won't be much of a
>>> problem I guess (?).
>>
>> If you don't mind it being slow, an easy way to get slices along
>> non-native axes is to convert the matrix format first.  For example,
>>
>>>>> csc.tocsr()[i, :]
>>
>> does the trick :)
>
> Okay!
>
> One more question related to this though ;-)
>
> Is there a function that does the equivalent of PySparse's dot(A,B) :=
> transp(A)*B in scipy sparse? I see a dot() but it looks like it  
> doesn't
> do the transpose...

Ah, this looks like a bug.  I'll try to fix this so dot() does take  
the transpose.  The current behaviour with transpose and conjugate  
operations seems inconsistent in a few other places.

> transp(A)*B ( or A*transp(B) depending on the compressed format) is  
> fast
> when done in 'one pass' as you don't need the transposition, but  
> slow if
> you do it with a transposition in python?

Actually, it's very fast if you have a CSR or CSC matrix, since it  
just toggles the format between the two.  It doesn't even need to  
copy the data.  So just use A.T * B for now, until I fix the dot  
function.  In your notation you'll want

sparse_matrix.T * sparse_matrix

-- Ed




More information about the SciPy-User mailing list