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

Nils Wagner nwagner at iam.uni-stuttgart.de
Wed May 17 04:38:19 EDT 2006


Ed Schofield wrote:
> On 17/05/2006, at 9:19 AM, Bram de Jong - MTG wrote:
>
>   
>> Hello everyone,
>>
>> ( First post on this list... Using SciPy in various algorithms and
>> extensions, all related to audio processing )
>>
>> * A simple question to start of with, is it correct to say that the
>> sparse matrices do not support slicing?
>>
>>     
>>> values = [0.1, 5.8, 21.8]
>>> indices = [[0,0],[1,1],[2,1]]
>>> matrix = sparse.coo_matrix(values, indices, 3, 3)
>>> matrix = matrix.tocsc()
>>> matrix2[1,1]
>>>       
>> 5.7999999999999998
>>     
>>> matrix2[1,:]
>>>       
>> Traceback (most recent call last):
>>    File "<input>", line 1, in ?
>>    File "C:\PYTHON23\lib\site-packages\scipy\sparse\Sparse.py", line
>> 578, in __getitem__
>>      raise KeyError, "Index out of bounds."
>> KeyError: 'Index out of bounds.'
>>
>> This using the scipy from the latest 'enthought' python installer for
>> windows.
>>     
>
> I've added some support for slicing in more recent SVN versions.   
> It's now possible to use csc[:, j], csr[i, :], or lil[i, :].  These  
> should be efficient operations.  But slicing along the 'non-native'  
> axes, with csc[i, :], csr[:, j], or lil[:, j] would be slower (and  
> more complex to write), and these raise an IndexError.
>
>   
>> * a not-so-simple question: is there any documentation, tutorial,
>> introduction, ... to the sparse matrices of scipy? It seems neither  
>> the
>> official (feebased) docs mention them, nor are the docstrings *that*
>> extensive.
>>     
>
> There are also more docstrings in SVN HEAD.  No tutorial yet,  
> although we've had several requests recently.  I'll see what I can do  
> after I've submitted my thesis in a few weeks ...
>
> -- Ed
>
>
> _______________________________________________
> SciPy-user mailing list
> SciPy-user at scipy.net
> http://www.scipy.net/mailman/listinfo/scipy-user
>   
BTW, I have submitted a bug report a few weeks ago

http://projects.scipy.org/scipy/scipy/ticket/40

Traceback (most recent call last):
  File "test_iterative.py", line 12, in ?
    x,info = linalg.gmres(A,b)
  File "/usr/lib64/python2.4/site-packages/scipy/linalg/iterative.py",
line 615, in gmres
    work[slice2] += sclr1*matvec(work[slice1])
ValueError: invalid return array shape
>>> A
matrix([[ 1.,  0.],
       [ 0.,  1.]])


Is it wanted that the input is restricted to arrays in linalg.gmres and
friends ?

Nils




More information about the SciPy-User mailing list