[Numpy-discussion] Slicing/selection in multiple dimensions simultaneously

David Warde-Farley dwf@cs.toronto....
Fri Feb 27 14:35:03 CST 2009

Hey Jon,

On 26-Feb-09, at 10:00 PM, Jonathan Taylor wrote:

> Am I right to assume that there is no way elegant way to interact with
> slices.  i.e. Is there anyway to get
> a[ix_([2,3,6],:,[3,2])]
> to work?  So that the dimension is completely specified?  Or perhaps
> the only way to do this is via
> a[ix_([2,3,6],range(a.shape[1]),[3,2])]
> If anyone knows a better way?

a[[2,3,6],:,:][:,:,[3,2]] should do what you want.

In [21]: a = randn(50,50,50)

In [22]: all(a[ix_([2,3,6],range(a.shape[1]),[3,2])] == a[[2,3,6],:,:] 
Out[22]: True


More information about the Numpy-discussion mailing list