[Numpy-discussion] Operations on masked items

Ryan May rmay31 at gmail.com
Tue Feb 3 18:00:42 EST 2009


Pierre GM wrote:
> On Feb 3, 2009, at 4:00 PM, Ryan May wrote:
>> Well, I guess I hit send too soon.  Here's one easy solution  
>> (consistent with
>> what you did for __radd__), change the code for __rmul__ to do:
>>
>> 	return multiply(self, other)
>>
>> instead of:
>>
>> 	return multiply(other, self)
>>
>> That fixes it for me, and I don't see how it would break anything.
> 
> Good call, but once again: "Thou shalt not put trust in ye masked  
> values [1]".
> 
>  >>> a = np.ma.array([1,2,3],mask=[0,1,0])
>  >>> b = np.ma.array([10, 20, 30], mask=[0,1,0])
>  >>> (a*b).data
> array([10,  2, 90])
>  >>> (b*a).data
> array([10, 20, 90])
> 
> So yes, __mul__ is not commutative when you deal w/ masked arrays (at  
> least, when you try to access the data under a mask). Nothing I can  
> do. Remember that preventing the underlying data to be modified is  
> NEVER guaranteed...

Fair enough.

Ryan

-- 
Ryan May
Graduate Research Assistant
School of Meteorology
University of Oklahoma



More information about the NumPy-Discussion mailing list