[Numpy-discussion] Operations on masked items
Ryan May
rmay31@gmail....
Tue Feb 3 14:54:37 CST 2009
Pierre,
I know you did some preliminary work on helping to make sure that doing
operations on masked arrays doesn't change the underlying data. I ran into the
following today.
import numpy as np
a = np.ma.array([1,2,3], mask=[False, True, False])
b = a * 10
c = 10 * a
print b.data # Prints [10 2 30] Good!
print c.data # Prints [10 10 30] Oops.
I tracked it down to __call__ on the _MaskedBinaryOperation class. If there's a
mask on the data, you use:
result = np.where(m, da, self.f(da, db, *args, **kwargs))
You can see that if a (and hence da) is a scalar, your masked values end up with
the value of the scalar. If this is getting too hairy to handle not touching
data, I understand. I just thought I should point out the inconsistency here.
Ryan
--
Ryan May
Graduate Research Assistant
School of Meteorology
University of Oklahoma
More information about the Numpy-discussion
mailing list