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

Travis Oliphant oliphant@enthought....
Tue Nov 17 13:24:21 CST 2009


On Nov 17, 2009, at 12:33 PM, Sebastian Haase 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".
> 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 !?

I don't think this is really a case of the way fancy indexing is  
implemented.  It could have been done in many ways.    The problem is  
one of real ambiguity in the general case and the fact that there  
wasn't any code written to handle the less ambiguous special-cases  
like this one.

There are real applications of index mixing, so turning it off is not  
an option.     We could perhaps add better handling of circumstances  
like this, however, with appropriate warnings and transitions.

-Travis





-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.scipy.org/pipermail/numpy-discussion/attachments/20091117/5d0273c1/attachment.html 


More information about the NumPy-Discussion mailing list