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

Robert Kern robert.kern@gmail....
Mon Mar 2 14:10:29 CST 2009

On Mon, Mar 2, 2009 at 13:10, David Warde-Farley <dwf@cs.toronto.edu> wrote:
> On 2-Mar-09, at 12:25 PM, Robert Kern wrote:
>> a[[2,3,6], ...][..., [3,2]]
>> You're doing fancy indexing, so there are copies both times.
> D'oh!
> So I guess the only way to avoid the second copy is to do what Jon
> initially suggested, i.e. a[ix_([2,3,6],range(a.shape[1]),[3,2])] ?
> I suppose xrange would be better than arange() or range() as it
> wouldn't create and destroy the list all at once.

I believe an array would be created from it, so arange() would be the
"best" bet there. But really, the difference is so trivial.

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

More information about the Numpy-discussion mailing list