[SciPy-User] Fancy indexing bug in sparse.lil_matrix?

Tony S Yu tonyyu at MIT.EDU
Fri Apr 2 15:13:19 EDT 2010


The scipy tutorial suggests that lil_matrix supports fancy indexing, but that doesn't seem to be completely true:

>>> from scipy import sparse
>>>
>>> N = 5
>>> A_lil = sparse.eye(N, N, format='lil')
>>> idx = range(N)
>>> print A_lil[idx, idx].todense()
[[ 1.  1.  1.  1.  1.]]
>>> A_lil[idx, idx] = 5
>>> print A_lil.todense()
[[ 5.  5.  5.  5.  5.]
 [ 5.  5.  5.  5.  5.]
 [ 5.  5.  5.  5.  5.]
 [ 5.  5.  5.  5.  5.]
 [ 5.  5.  5.  5.  5.]]

In the above code, getting the main diagonal works as expected, but setting the main diagonal produces unexpected results. Is this a known issue?

This issue doesn't seem to be the same as Ticket #1064 (plus, I believe that issue is fixed in my version of scipy).

-Tony
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.scipy.org/pipermail/scipy-user/attachments/20100402/35ae5651/attachment.html>


More information about the SciPy-User mailing list