# [Scipy-tickets] [SciPy] #226: sparse.lil_matrix doesn't support inplace operations with fancy indexing

SciPy scipy-tickets@scipy....
Tue Feb 19 13:48:54 CST 2008

#226: sparse.lil_matrix doesn't support inplace operations with fancy indexing
--------------------------+-------------------------------------------------
Reporter:  NeilenMarais  |        Owner:  edschofield
Type:  enhancement   |       Status:  assigned
Priority:  normal        |    Milestone:  0.7
Component:  scipy.sparse  |      Version:
Severity:  normal        |   Resolution:
Keywords:                |
--------------------------+-------------------------------------------------
Comment (by nils):

The current behavior is as follows

{{{
>>> from scipy import sparse
>>> mat = sparse.lil_matrix((5,5))
>>> mat[[0,2,4], 0] = [1,2,3]
>>> mat.todense()
matrix([[ 1.,  0.,  0.,  0.,  0.],
[ 0.,  0.,  0.,  0.,  0.],
[ 2.,  0.,  0.,  0.,  0.],
[ 0.,  0.,  0.,  0.,  0.],
[ 3.,  0.,  0.,  0.,  0.]])
>>> from numpy import array
>>> mat[[0,2,4], 0] += array([1,2,3])
>>> mat.todense()
Traceback (most recent call last):
File "<stdin>", line 1, in ?
File "/usr/lib/python2.4/site-packages/scipy/sparse/base.py", line 416,
in todense
return asmatrix(self.toarray())
File "/usr/lib/python2.4/site-packages/scipy/sparse/lil.py", line 399,
in toarray
d[i, j] = self.data[i][pos]
ValueError: setting an array element with a sequence.
>>> from numpy import arange
>>> mat[1, [0,2,4]] = arange(3)+1
>>> mat.todense()
Traceback (most recent call last):
File "<stdin>", line 1, in ?
File "/usr/lib/python2.4/site-packages/scipy/sparse/base.py", line 416,
in todense
return asmatrix(self.toarray())
File "/usr/lib/python2.4/site-packages/scipy/sparse/lil.py", line 399,
in toarray
d[i, j] = self.data[i][pos]
ValueError: setting an array element with a sequence.
}}}

--
Ticket URL: <http://scipy.org/scipy/scipy/ticket/226#comment:3>
SciPy <http://www.scipy.org/>
SciPy is open-source software for mathematics, science, and engineering.