[Numpy-discussion] Strange inversion in shape with some slices

Sebastian Haase seb.haase@gmail....
Tue Nov 17 12:33:29 CST 2009


On Tue, Nov 17, 2009 at 5:40 PM,  <josef.pktd@gmail.com> wrote:
> On Tue, Nov 17, 2009 at 11:24 AM, Jean-Baptiste Rudant
> <boogaloojb@yahoo.fr> wrote:
>> Hello,
>> I think there's something strange with shape when a slice is given by an
>> array.
>> import numpy as N
>> my_array = N.ones((2, 3, 6))
>> ind = N.arange(4)
>> #you hope to find (3, 4)
>> print my_array[0, :, ind].shape
>> print my_array[0, :, 0:4].shape
>> print my_array[0][:, ind].shape
>> print my_array[0][:, 0:4].shape
>> """
>> (4, 3)
>> (3, 4)
>> (3, 4)
>> (3, 4)
>> """
>> Jean-Baptiste Rudant
>
> there was a long thread on this with the explanation in March, title
> "is it a bug?"
>
The thread is here:
http://www.mail-archive.com/numpy-discussion@scipy.org/msg16300.html

It looks to me like violating the principle of "least surprise".
My reading of that thread is, that the observed "bug" is mostly a
consequence coming from the way fancy indexing is implemented. How
about deprecating this kind of index mixing !?

Regards,
Sebastian Haase


More information about the NumPy-Discussion mailing list