[Numpy-discussion] Conditional update of recarray field
Wed Nov 28 09:15:52 CST 2012
I got it. Thanks! Now I see why this is non-trivial to fix it.
However, it might be also a source of very-hard-to-find bugs. It might
be worth discussing this non-intuitive example in the documentation.
>> 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
More information about the NumPy-Discussion