[SciPy-user] scipy.sparse.lil_matrix and fancy indexing
David Warde-Farley
dwf@cs.toronto....
Sun Feb 3 17:16:24 CST 2008
On 3-Feb-08, at 5:29 PM, Anne Archibald wrote:
> In [22]: print B
> (0, 0) 1
> (0, 1) 1
> (0, 2) 1
> (1, 0) 1
> (1, 1) 1
> (1, 2) 1
> (2, 0) 1
> (2, 1) 1
> (2, 2) 1
I agree that this isn't what you'd expect, since it works completely
differently on arrays. The equivalent behaviour for a numpy.array
would be obtained by using A[0:3,:][:,0:3], and to add to the list of
unexpected behaviours, lil_matrix accepts this type of indexing
without raising an error but doesn't actually do anything then:
In [18]: A = scipy.sparse.lil_matrix((3,3))
In [19]: x[0:3,:][:,0:3] = 1
In [20]: x
Out[20]:
<3x3 sparse matrix of type '<type 'numpy.float64'>'
with 0 stored elements in LInked List format>
David
More information about the SciPy-user
mailing list