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

Stéfan van der Walt stefan@sun.ac...
Wed Feb 8 17:54:42 CST 2012


On Wed, Feb 8, 2012 at 6:49 AM, Travis Oliphant <travis@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 arrays: i = arange(arr.shape[0]) and j = arange(arr.shape[1]), and depth is a 2-d array of "depths".   The selected result will be 2-d.

For those of you new to fancy indexing and broadcasting, have a look
at the Advanced NumPy Tutorial slides from SciPy2008:

http://mentat.za.net/numpy/numpy_advanced_slides/

It also includes an example like the one Travis mentioned.

Regards
Stéfan


More information about the NumPy-Discussion mailing list