[Numpy-discussion] Is this an indexing bug?
Wed Jun 20 15:30:12 CDT 2007
Travis Oliphant schrieb:
> Sturla Molden wrote:
>> >>> x = numpy.arange(100).reshape((1,10,10))
>> >>> x[0,:,numpy.arange(5)].shape
>> (5, 10)
>> >>> x[:,:,numpy.arange(5)].shape
>> (1, 10, 5)
>> It looks like a bug that needs to be squashed.
> These are both correct. See my previous posts about the rule.
> The first case is exactly the example we saw before: we start with a
> (1,10,10)-shaped array and replace the first and last-dimension
> (1,10)-shaped array with a (5,)-shaped array. Not having a clear place
> to put the extracted (5,)-shaped subspace, it is tacked on to the front.
> In the second example, the last-dimension (10,)-shaped sub-space is
> replaced with a (5,)-shaped sub-space. There is no ambiguity in this
> case and the result is a (1,10,5)-shaped array.
> There is no bug here. Perhaps unexpected behavior with "advanced
> indexing" combined with single-integer indexing in separated dimensions
> but no bug. The result, does follow an understandable and generalizable
Thanks for the explanation. Maybe some of these examples could be added
to the relevant section of the book. Although I must say I'm glad that I
currently don't need to use this stuff, I'm not sure I would get it
More information about the Numpy-discussion