[SciPy-User] Indexing sparse matrices with step

Warren Weckesser warren.weckesser@enthought....
Thu Feb 2 20:46:42 CST 2012


On Thu, Feb 2, 2012 at 10:52 AM, Pascal Lamblin
<lamblinp@iro.umontreal.ca>wrote:

> Hi everybody,
>
> I've noticed that if I have a scipy.sparse matrix (csr or csc), and I
> try to index into it with slices, the "step" component of my slice seems
> to be silently ignored.
>
> Is it an expected behaviour? I would have expected an error saying only
> a step of None (or not providing a step at all) is supported.
>
> Here is a small test case:
>
> import numpy, scipy.sparse
>
> sm = scipy.sparse.csc_matrix([[1, 0, 0], [0, 0, 0], [0, 0, 0], [0, 1, 0]])
>
> # True, expected
> numpy.all(sm[:1,:].toarray() == sm.toarray()[:1,:])
>
> # False, expected
> numpy.all(sm.toarray()[:1,:] == sm.toarray()[:1:-1,:])
>
> # True, unexpected
> numpy.all(sm[:1:-1,:].toarray() == sm[:1,:].toarray())
>
> # False, unexpected
> numpy.all(sm[:1:-1,:].toarray() == sm.toarray()[:1:-1,:])
>
>

Looks like a bug.  I've created a ticket:
http://projects.scipy.org/scipy/ticket/1592

Thanks for reporting the problem.

Warren
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.scipy.org/pipermail/scipy-user/attachments/20120202/4aa4406c/attachment.html 


More information about the SciPy-User mailing list