[Scipy-tickets] [SciPy] #1526: sparse.lil_matrix assigment bug when indexing with two lists
SciPy Trac
scipy-tickets@scipy....
Thu Sep 29 07:06:15 CDT 2011
#1526: sparse.lil_matrix assigment bug when indexing with two lists
-----------------------------+----------------------------------------------
Reporter: tony.stillfjord | Owner: wnbell
Type: defect | Status: new
Priority: normal | Milestone: 0.10.0
Component: scipy.sparse | Version: 0.9.0
Keywords: |
-----------------------------+----------------------------------------------
With a scipy.sparse.lil_matrix A, assignments of the form A[L1, L2] = 0,
where L1 and L2 are two index lists, give the wrong results. If either L1
or L2 is a single index it works fine. Only accessing the matrix with
A[L1, L2] also gives the right elements, it is just the assignment part
that fails. Exchanging the 0 with an array of the correct length does not
help.
The faulty behaviour seems to be equivalent to A[min(L1):max(L1)+1,
min(L2):max(L2)+1] = 0 but I'm not completely sure. The code below
illustrates the bug:
import numpy
import scipy.sparse
B = numpy.array([[1,2,3],[3,4,5],[6,7,8]])
A = scipy.sparse.lil_matrix(B)
print 'A:', A.todense()
print 'B:', B
print 'Some A-elements:', A[[0,1,2],[1,2,0]].todense()
print 'Some B-elements:', B[[0,1,2],[1,2,0]]
B[[0,1,2],[1,2,0]] = 0
print 'New B:', B
A[[0,1,2],[1,2,0]] = 0
print 'New A:', A.todense()
Output:
A: [[1 2 3]
[3 4 5]
[6 7 8]]
B: [[1 2 3]
[3 4 5]
[6 7 8]]
Some A-elements: [[2 5 6]]
Some B-elements: [2 5 6]
New B: [[1 0 3]
[3 4 0]
[0 7 8]]
New A: [[0 0 0]
[0 0 0]
[0 0 0]]
--
Ticket URL: <http://projects.scipy.org/scipy/ticket/1526>
SciPy <http://www.scipy.org>
SciPy is open-source software for mathematics, science, and engineering.
More information about the Scipy-tickets
mailing list