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

2009-11-17 Thread josef . pktd
On Tue, Nov 17, 2009 at 11:24 AM, Jean-Baptiste Rudant
boogalo...@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?

Josef



 ___
 NumPy-Discussion mailing list
 NumPy-Discussion@scipy.org
 http://mail.scipy.org/mailman/listinfo/numpy-discussion


___
NumPy-Discussion mailing list
NumPy-Discussion@scipy.org
http://mail.scipy.org/mailman/listinfo/numpy-discussion


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

2009-11-17 Thread Sebastian Haase
On Tue, Nov 17, 2009 at 5:40 PM,  josef.p...@gmail.com wrote:
 On Tue, Nov 17, 2009 at 11:24 AM, Jean-Baptiste Rudant
 boogalo...@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
___
NumPy-Discussion mailing list
NumPy-Discussion@scipy.org
http://mail.scipy.org/mailman/listinfo/numpy-discussion


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

2009-11-17 Thread Robert Kern
On Tue, Nov 17, 2009 at 12:33, Sebastian Haase seb.ha...@gmail.com wrote:
 On Tue, Nov 17, 2009 at 5:40 PM,  josef.p...@gmail.com wrote:
 On Tue, Nov 17, 2009 at 11:24 AM, Jean-Baptiste Rudant
 boogalo...@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
___
NumPy-Discussion mailing list
NumPy-Discussion@scipy.org
http://mail.scipy.org/mailman/listinfo/numpy-discussion


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

2009-11-17 Thread Travis Oliphant


On Nov 17, 2009, at 12:33 PM, Sebastian Haase wrote:


On Tue, Nov 17, 2009 at 5:40 PM,  josef.p...@gmail.com wrote:

On Tue, Nov 17, 2009 at 11:24 AM, Jean-Baptiste Rudant
boogalo...@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





___
NumPy-Discussion mailing list
NumPy-Discussion@scipy.org
http://mail.scipy.org/mailman/listinfo/numpy-discussion