[Numpy-discussion] Strange inversion in shape with some slices
Robert Kern
robert.kern@gmail....
Tue Nov 17 12:41:30 CST 2009
On Tue, Nov 17, 2009 at 12:33, Sebastian Haase <seb.haase@gmail.com> wrote:
> 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".
That "principle" is notoriously unreliable, and I am never convinced by it.
> 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 !?
No. When you need it, you need it.
--
Robert Kern
"I have come to believe that the whole world is an enigma, a harmless
enigma that is made terrible by our own mad attempt to interpret it as
though it had an underlying truth."
-- Umberto Eco
More information about the NumPy-Discussion
mailing list