[Numpy-discussion] List of indices

Friedrich Romstedt friedrichromstedt@gmail....
Thu Apr 8 16:44:33 CDT 2010


2010/4/2 Shailendra <shailendra.vikas@gmail.com>:
>>>> x=arange(10)
>>>> indices=[(1,),(2,)]
>>>> x[indices]
> Traceback (most recent call last):
>  File "<stdin>", line 1, in <module>
> IndexError: unsupported iterator index

I have more odd things to report (numpy 1.4.0):

>>> b = numpy.asarray([[1, 2], [3, 4]])
>>> b[[(0, 0)]]
array([[1, 2],
       [1, 2]])

How does the advanced integer indicing mode work precisely?  The docu
(http://docs.scipy.org/doc/numpy/reference/arrays.indexing.html#integer)
says: "All sequences and scalars in the selection tuple are converted
to intp indexing arrays."  How can then numpy distinguish between
lists and tuples?  My thought is, that maybe only the lists are taken
into account to calculate the broadcasting target, and tuples are
handed over to the indicing step, as described in the docu.  But then,
it seems, that length-1 items are "flattened"?

Friedrich


More information about the NumPy-Discussion mailing list