[Numpy-discussion] Getting an item in an array with its coordinates given by another array
Mon Oct 29 08:36:32 CDT 2007
On 10/28/07, Matthieu Brucher <firstname.lastname@example.org> wrote:
> > Little correction, only c[(2,3)] gives me what I expect, not c[[2,3]],
> > which
> > > is even stranger.
> > c[(2,3)] is the same as c[2,3] and obviously works as you expected.
> Well, this is not indicated in the documentation.
This is true at the Python level and is not related to numpy. "x=c[2,3]" is
equivalent to "x=c.__getitem__((2,3))". Note that the index pair is passed
as a tuple. On the other hand, a single index is not passed as a tuple, but
is instead passed as is. For example: "x = c[a]" gets passed as
"x=c.__getitem__(a)". If 'a' happens to be '(2,3)' you get the behavior
So, although lists and arrays can be used for "fancy-indexing", tuples
cannot be since you can't tell the difference between a tuple of indices and
multiple indices inside square brackets.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Numpy-discussion