[Scipy-tickets] [SciPy] #1592: 'step' field of a slice of a csc or csr sparse matrix is ignored.

SciPy Trac scipy-tickets@scipy....
Thu Feb 2 20:41:06 CST 2012


#1592: 'step' field of a slice of a csc or csr sparse matrix is ignored.
-------------------------------------------+--------------------------------
 Reporter:  warren.weckesser               |       Owner:  wnbell     
     Type:  defect                         |      Status:  new        
 Priority:  normal                         |   Milestone:  Unscheduled
Component:  scipy.sparse                   |     Version:  devel      
 Keywords:  csc_matrix, csr_matrix, slice  |  
-------------------------------------------+--------------------------------
 Reported by Pascal Lamblin on the scipy-user mailing list:
 {{{
 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,:])
 }}}

 Here's another broken example:
 {{{
 In [30]: a = csc_matrix([[1,0,2],[0,0,3],[4,5,6]])

 In [31]: a.todense()
 Out[31]:
 matrix([[1, 0, 2],
         [0, 0, 3],
         [4, 5, 6]])

 In [32]: a[0::2,0::2].todense()
 Out[32]:
 matrix([[1, 0, 2],
         [0, 0, 3],
         [4, 5, 6]])

 In [33]: a.todense()[0::2,0::2]
 Out[33]:
 matrix([[1, 2],
         [4, 6]])
 }}}

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


More information about the Scipy-tickets mailing list