[Scipy-tickets] [SciPy] #1075: Fixing lil_matrix column slicing broke case with sequences for both index arguments.

SciPy Trac scipy-tickets@scipy....
Fri Feb 4 19:35:22 CST 2011


#1075: Fixing lil_matrix column slicing broke case with sequences for both index
arguments.
--------------------------+-------------------------------------------------
 Reporter:  timv          |       Owner:  wnbell
     Type:  defect        |      Status:  new   
 Priority:  high          |   Milestone:  0.9.0 
Component:  scipy.sparse  |     Version:  devel 
 Keywords:                |  
--------------------------+-------------------------------------------------
Changes (by warren.weckesser):

  * priority:  normal => high


Comment:

 Bumping up the priority.  Both lil_matrix and dok_matrix behave
 differently compared to a numpy.ndarray and numpy.matrix:
 {{{
 In [1]: from scipy.sparse import lil_matrix, dok_matrix

 In [2]: a = zeros((5,5))   # dense array; numpy's matrix also behaves like
 this.

 In [3]: a[range(5),range(5)] = -1

 In [4]: a
 Out[4]:
 array([[-1.,  0.,  0.,  0.,  0.],
        [ 0., -1.,  0.,  0.,  0.],
        [ 0.,  0., -1.,  0.,  0.],
        [ 0.,  0.,  0., -1.,  0.],
        [ 0.,  0.,  0.,  0., -1.]])

 In [5]: b = lil_matrix((5,5))   # sparse LIL matrix.

 In [6]: b[range(5),range(5)] = -1

 In [7]: b.todense()
 Out[7]:
 matrix([[-1., -1., -1., -1., -1.],
         [-1., -1., -1., -1., -1.],
         [-1., -1., -1., -1., -1.],
         [-1., -1., -1., -1., -1.],
         [-1., -1., -1., -1., -1.]])

 In [8]: c = dok_matrix((5,5))   # sparse DOK matrix.

 In [9]: c[range(5),range(5)] = -1

 In [10]: c.todense()
 Out[10]:
 matrix([[-1., -1., -1., -1., -1.],
         [-1., -1., -1., -1., -1.],
         [-1., -1., -1., -1., -1.],
         [-1., -1., -1., -1., -1.],
         [-1., -1., -1., -1., -1.]])
 }}}

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


More information about the Scipy-tickets mailing list