Re: [Numpy-discussion] Logical indexing and higher-dimensional arrays.

2012-02-08 Thread Stéfan van der Walt
On Tue, Feb 7, 2012 at 9:01 PM, Travis Oliphant tra...@continuum.io wrote: like so:  x[ind1, :, ind2], the question is what should the shape of the output me.   If ind1 is a scalar there is no ambiguity (and this should be special cased --- but unfortunately isn't). If x.shape == (a0, a1,

Re: [Numpy-discussion] Logical indexing and higher-dimensional arrays.

2012-02-08 Thread Olivier Delalleau
Le 8 février 2012 00:01, Travis Oliphant tra...@continuum.io a écrit : On Feb 7, 2012, at 12:24 PM, Sturla Molden wrote: On 07.02.2012 19:17, Benjamin Root wrote: print x.shape (2, 3, 4) print x[0, :, :].shape (3, 4) print x[0, :, idx].shape (2, 3) That looks like a bug to

Re: [Numpy-discussion] Logical indexing and higher-dimensional arrays.

2012-02-08 Thread Sturla Molden
On 08.02.2012 06:01, Travis Oliphant wrote: Recall that the shape of the output with fancy indexing is determined by broadcasting together the indexing objects and using that as the shape of the output: x[ind1, ind2] will produce an output with the shape of broadcast(ind1, ind2) whose

Re: [Numpy-discussion] Logical indexing and higher-dimensional arrays.

2012-02-08 Thread Travis Oliphant
On Feb 8, 2012, at 8:29 AM, Sturla Molden wrote: On 08.02.2012 06:01, Travis Oliphant wrote: Recall that the shape of the output with fancy indexing is determined by broadcasting together the indexing objects and using that as the shape of the output: x[ind1, ind2] will produce an

Re: [Numpy-discussion] Logical indexing and higher-dimensional arrays.

2012-02-08 Thread Sturla Molden
On 08.02.2012 15:11, Olivier Delalleau wrote: From a user perspective, I would definitely prefer cross-product semantics for fancy indexing. In fact, I had never used fancy indexing with more than one array index, so the behavior described in this thread totally baffled me. If for instance x

Re: [Numpy-discussion] Logical indexing and higher-dimensional arrays.

2012-02-08 Thread Sturla Molden
On 08.02.2012 15:49, Travis Oliphant wrote: This sort of thing would take time, but is not out of the question in my mind because I suspect the number of users and use-cases of broadcasted fancy-indexing is small. In Matlab this (misfeature?) is generally used to compensate for the lack of

Re: [Numpy-discussion] Logical indexing and higher-dimensional arrays.

2012-02-08 Thread josef . pktd
On Wed, Feb 8, 2012 at 10:29 AM, Sturla Molden stu...@molden.no wrote: On 08.02.2012 15:49, Travis Oliphant wrote: This sort of thing would take time, but is not out of the question in my mind because I suspect the number of users and use-cases of broadcasted fancy-indexing is small. I

Re: [Numpy-discussion] Logical indexing and higher-dimensional arrays.

2012-02-08 Thread Sturla Molden
On 08.02.2012 18:17, josef.p...@gmail.com wrote: I think I use it quite a bit, and I like that the broadcasting in indexing is as flexible as the broadcasting of numpy arrays themselves. x[np.arange(len(x)), np.arange(len(x))] gives the diagonal for example. Personally I would prefer that

Re: [Numpy-discussion] Logical indexing and higher-dimensional arrays.

2012-02-08 Thread Aronne Merrelli
On Wed, Feb 8, 2012 at 8:49 AM, Travis Oliphant tra...@continuum.io wrote: On Feb 8, 2012, at 8:29 AM, Sturla Molden wrote: On 08.02.2012 06:01, Travis Oliphant wrote: Recall that the shape of the output with fancy indexing is determined by broadcasting together the indexing objects and

Re: [Numpy-discussion] Logical indexing and higher-dimensional arrays.

2012-02-08 Thread Travis Oliphant
On Feb 8, 2012, at 11:17 AM, josef.p...@gmail.com wrote: On Wed, Feb 8, 2012 at 10:29 AM, Sturla Molden stu...@molden.no wrote: On 08.02.2012 15:49, Travis Oliphant wrote: This sort of thing would take time, but is not out of the question in my mind because I suspect the number of users

Re: [Numpy-discussion] Logical indexing and higher-dimensional arrays.

2012-02-08 Thread Robert Kern
On Wed, Feb 8, 2012 at 22:11, Travis Oliphant tra...@continuum.io wrote: On Feb 8, 2012, at 11:17 AM, josef.p...@gmail.com wrote: On Wed, Feb 8, 2012 at 10:29 AM, Sturla Molden stu...@molden.no wrote: On 08.02.2012 15:49, Travis Oliphant wrote: This sort of thing would take time, but is not

Re: [Numpy-discussion] Logical indexing and higher-dimensional arrays.

2012-02-08 Thread Travis Oliphant
On Feb 8, 2012, at 4:19 PM, Robert Kern wrote: On Wed, Feb 8, 2012 at 22:11, Travis Oliphant tra...@continuum.io wrote: On Feb 8, 2012, at 11:17 AM, josef.p...@gmail.com wrote: On Wed, Feb 8, 2012 at 10:29 AM, Sturla Molden stu...@molden.no wrote: On 08.02.2012 15:49, Travis Oliphant

Re: [Numpy-discussion] Logical indexing and higher-dimensional arrays.

2012-02-08 Thread Stéfan van der Walt
On Wed, Feb 8, 2012 at 6:49 AM, Travis Oliphant tra...@continuum.io wrote: There are also some very nice applications where you can select out of a 3-d volume a depth-surface defined by indexes like so:        arr[ i[:,newaxis], j, depth] where arr is a 3-d array,  i and j are 1-d index

[Numpy-discussion] Logical indexing and higher-dimensional arrays.

2012-02-07 Thread Jordi Gutiérrez Hermoso
Consider the following. Is this a bug? Thanks, - Jordi G. H. --- #!/usr/bin/python import numpy as np x = np.reshape(np.random.uniform(size=2*3*4), [2,3,4]) idx = np.array([False, True, False, True]) y = x[0,:,:]; ## Why is this transposed? print

Re: [Numpy-discussion] Logical indexing and higher-dimensional arrays.

2012-02-07 Thread Benjamin Root
On Tue, Feb 7, 2012 at 11:11 AM, Jordi Gutiérrez Hermoso jord...@octave.org wrote: Consider the following. Is this a bug? Thanks, - Jordi G. H. --- #!/usr/bin/python import numpy as np x = np.reshape(np.random.uniform(size=2*3*4), [2,3,4])

Re: [Numpy-discussion] Logical indexing and higher-dimensional arrays.

2012-02-07 Thread Sturla Molden
On 07.02.2012 19:17, Benjamin Root wrote: print x.shape (2, 3, 4) print x[0, :, :].shape (3, 4) print x[0, :, idx].shape (2, 3) That looks like a bug to me. The length of the first dimension should be the same. Sturla ___

Re: [Numpy-discussion] Logical indexing and higher-dimensional arrays.

2012-02-07 Thread Sturla Molden
On 07.02.2012 19:24, Sturla Molden wrote: On 07.02.2012 19:17, Benjamin Root wrote: print x.shape (2, 3, 4) print x[0, :, :].shape (3, 4) print x[0, :, idx].shape (2, 3) That looks like a bug to me. The length of the first dimension should be the same. I can reproduce this

Re: [Numpy-discussion] Logical indexing and higher-dimensional arrays.

2012-02-07 Thread Stéfan van der Walt
On Tue, Feb 7, 2012 at 10:41 AM, Sturla Molden stu...@molden.no wrote: It's the combination of a single index and fancy indexing that does this, not the slicing. There are some quirks in the broadcasting machinery that makes it almost impossible to guess what the outcome of mixed indexing is

Re: [Numpy-discussion] Logical indexing and higher-dimensional arrays.

2012-02-07 Thread Travis Oliphant
This comes up from time to time.This is an example of what is described at the top of page 84 of Guide to NumPy. Also read Chapter 17 to get the explanation of how fancy indexing is implemented if you really want to understand the issues. When you mix fancy-indexing with simple indexing,

Re: [Numpy-discussion] Logical indexing and higher-dimensional arrays.

2012-02-07 Thread Travis Oliphant
On Feb 7, 2012, at 12:24 PM, Sturla Molden wrote: On 07.02.2012 19:17, Benjamin Root wrote: print x.shape (2, 3, 4) print x[0, :, :].shape (3, 4) print x[0, :, idx].shape (2, 3) That looks like a bug to me. The length of the first dimension should be the same. What you are