[Numpy-discussion] List of indices

Shailendra shailendra.vikas@gmail....
Fri Apr 2 11:34:06 CDT 2010


Hi All,

>>> x=arange(10)
>>> indices=[(1,),(2,)]
>>> x[indices]
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
IndexError: unsupported iterator index


But following works.
>>> x=x.reshape(5,2)
>>> x
array([[0, 1],
       [2, 3],
       [4, 5],
       [6, 7],
       [8, 9]])
>>> indices=[(1,0),(0,1)]
>>> x[indices]
array([2, 1])



Should not the first one also work? How to convert [(1,),(2,)] to
[1,2] efficiently.

Thanks,
Shailendra


More information about the NumPy-Discussion mailing list