thouis / numpy-trac-migration

numpy Trac to github issues migration
2 stars 3 forks source link

1d array can't be accessed with a tuple. (Trac #2217) #6006

Open numpy-gitbot opened 12 years ago

numpy-gitbot commented 12 years ago

Original ticket http://projects.scipy.org/numpy/ticket/2217 on 2012-09-18 by trac user laket, assigned to unknown.

Using a tuple to access elements of 1d array, I got IndexError,

>>>c = numpy.array([1,2,3])
>>>c[(0,1)]

IndexError: invalid index

When I accessed 2d array with a tuple, I got expected result.

>>> c = numpy.array([[1,2],[3,4]])
>>> c[:,(0,1)]
array([[1, 2],
       [3, 4]])

Python : 2.7.3 Numpy : 1.6.1 OS : Ubuntu 12.04

numpy-gitbot commented 12 years ago

trac user seberg wrote on 2012-09-20

It is not a bug, its a detail about how python parses tuples (and the slice syntax). (c[0,1] parses to the same thing as c[(0,1)]).

The simple fix is, always use lists or arrays for fancy indexing. Numpy tolerates tuples in many cases like the second, but it simply cannot allow them in general.