[Numpy-discussion] Operations on masked items
Pierre GM
pgmdevlist@gmail....
Tue Feb 3 15:19:16 CST 2009
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...
[1] Epistle of Paul (Dubois).
More information about the Numpy-discussion
mailing list