[Numpy-discussion] Unexpected MaskedArray behavior

Pierre GM pgmdevlist@gmail....
Tue Dec 16 17:48:52 CST 2008


On Dec 16, 2008, at 1:57 PM, Ryan May wrote:

> I just noticed the following and I was kind of surprised:
>
>>>> a = ma.MaskedArray([1,2,3,4,5], mask=[False,True,True,False,False])
>>>> b = a*5
>>>> b
> masked_array(data = [5 -- -- 20 25],
>       mask = [False  True  True False False],
>       fill_value=999999)
>>>> b.data
> array([ 5, 10, 15, 20, 25])
>
> I was expecting that the underlying data wouldn't get modified while  
> masked.  Is
> this actual behavior expected?

Meh. Masked data shouldn't be trusted anyway, so I guess it doesn't  
really matter one way or the other.
But I tend to agree, it'd make more sense leave masked data untouched  
(or at least, reset them to their original value after the operation),  
which would mimic the behavior of gimp/photoshop.
Looks like there's a relatively easy fix. I need time to check whether  
it doesn't break anything elsewhere, nor that it slows things down too  
much. I won't have time to test all that before next week, though. In  
any case, that would be for 1.3.x, not for 1.2.x.
In the meantime, if you need the functionality, use something like
ma.where(a.mask,a,a*5)



More information about the Numpy-discussion mailing list