[Numpy-discussion] masked arrays as array indices (is a bad idea)

Pierre GM pgmdevlist@gmail....
Mon Sep 21 15:35:58 CDT 2009

On Sep 21, 2009, at 4:23 PM, Ernest Adrogué wrote:
> This explains why x[x == 3] = 4 works "as expected", whereas
> x[x == 0] = 4 ruins everything. Basically, any condition that matches
> 0 will match every masked item as well.

There's room for improvement here indeed. I need to check first  
whether fixing the comparison methods doesn't break anything.

> I don't know, but maybe it would be better to raise an exception when
> the index is a masked array then. The current behaviour seems a bit
> confusing to me.

That'd be modifying ndarray.__getitem__ and I don't see that  
happening. In the meantime, please just fill your masked array with  
the `filled` method or the corresponding function.
Remmber that masked arrays are for convenience. As soon as you try to  
do some heavy computations, you're better processing data and mask  

More information about the NumPy-Discussion mailing list