[Numpy-tickets] [NumPy] #578: Indexing of multi-D arrays is counterintuitive

NumPy numpy-tickets@scipy....
Thu Sep 13 09:30:57 CDT 2007


#578: Indexing of multi-D arrays is counterintuitive
------------------------+---------------------------------------------------
 Reporter:  gic888      |       Owner:  somebody     
     Type:  defect      |      Status:  new          
 Priority:  normal      |   Milestone:  1.0.4 Release
Component:  numpy.core  |     Version:  none         
 Severity:  normal      |    Keywords:               
------------------------+---------------------------------------------------
 numpy 1.0.4.dev3869 with Python 2.5 on Mac OS 10.4.9 (Intel)

 Slicing 1 dimension of a 2D array does not have the same effect as using
 the same slice on a 1D array. Also, calling "array" on the slice generates
 an array different than the slice, and some slice indexes behave
 differently than others. I will clarify with examples:

 ipy > z=reshape(arange(30), (15,2))
 ipy > z[3:,0]=z[:-3,0]

 ipy > z
  out:
 array([[ 0,  1],
        [ 2,  3],
        [ 4,  5],
        [ 0,  7],
        [ 2,  9],
        [ 4, 11],
        [ 0, 13],
        [ 2, 15],
        [ 4, 17],
        [ 0, 19],
        [ 2, 21],
        [ 4, 23],
        [ 0, 25],
        [ 2, 27],
        [ 4, 29]])

 but:

 ipy > z=reshape(arange(30), (15,2))
 ipy > z[:-3,0]=z[3:,0]
 ipy > z
  out:
 array([[ 6,  1],
        [ 8,  3],
        [10,  5],
        [12,  7],
        [14,  9],
        [16, 11],
        [18, 13],
        [20, 15],
        [22, 17],
        [24, 19],
        [26, 21],
        [28, 23],
        [24, 25],
        [26, 27],
        [28, 29]])

 and:

 ipy > z=reshape(arange(30), (15,2))

 ipy > z[3:,0]=array(z[:-3,0])

 ipy > z
  out:
 array([[ 0,  1],
        [ 2,  3],
        [ 4,  5],
        [ 0,  7],
        [ 2,  9],
        [ 4, 11],
        [ 6, 13],
        [ 8, 15],
        [10, 17],
        [12, 19],
        [14, 21],
        [16, 23],
        [18, 25],
        [20, 27],
        [22, 29]])

-- 
Ticket URL: <http://scipy.org/scipy/numpy/ticket/578>
NumPy <http://projects.scipy.org/scipy/numpy>
The fundamental package needed for scientific computing with Python.


More information about the Numpy-tickets mailing list