[Numpy-discussion] Conditional update of recarray field

Francesc Alted francesc at continuum.io
Wed Nov 28 09:36:50 EST 2012

Hey Bartosz,

On 11/28/12 3:26 PM, Bartosz wrote:
> Thanks for answer, Francesc.
> I understand now that fancy indexing returns a copy of a recarray. Is
> it also true for standard ndarrays? If so, I do not understand why
> X['a'][cond]=-1 should work.

Yes, that's a good question.  No, in this case the boolean array `cond` 
is passed to the __setitem__() of the original view, so this is why this 
works.  The first idiom is concatenating the fancy indexing with another 
indexing operation, and NumPy needs to create a temporary for executing 
this, so the second indexing operation acts over a copy, not a view.

And yes, fancy indexing returning a copy is standard for all ndarrays.

Hope it is clearer now (although admittedly it is a bit strange at first 

Francesc Alted

More information about the NumPy-Discussion mailing list