[Numpy-discussion] Resending: List of indices

Shailendra shailendra.vikas@gmail....
Sun Apr 4 09:05:03 CDT 2010


On Fri, Apr 2, 2010 at 12:34 PM, Shailendra <shailendra.vikas@gmail.com> wrote:
> 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