[Numpy-discussion] MA - math operations do not preserve fill_value
Joe Van Andel
vanandel at atd.ucar.edu
Tue Nov 6 13:15:04 EST 2001
Using Python 2.1 and Numeric 20.2.1 on Redhat Linux 7.1
Shouldn't masked arrays preserve the fill value of their operands, if
both operands have the same fill value? Otherwise, if I want to
preserve the value of the fill_value, I have to write expressions like:
d=masked_values((a+b),a.fill_value())
Here's a demonstration of the problem:
>>> a = masked_values((1.0,2.0,3.0,4.0,-999.0), -999)
>>> b = masked_values((-999.0,1.0,2.0,3.0,4.0), -999)
>>> a
array(data =
[ 1., 2., 3., 4.,-999.,],
mask =
[0,0,0,0,1,],
fill_value=-999)
>>> b
array(data =
[-999., 1., 2., 3., 4.,],
mask =
[1,0,0,0,0,],
fill_value=-999)
>>> c=a+b
>>> c
array(data =
[ 1.00000002e+20, 3.00000000e+00, 5.00000000e+00, 7.00000000e+00,
1.00000002e+20,],
mask =
[1,0,0,0,1,],
fill_value=[ 1.00000002e+20,])
>>> d=masked_values((a+b),a.fill_value())
>>> d
array(data =
[-999., 3., 5., 7.,-999.,],
mask =
[1,0,0,0,1,],
fill_value=-999)
--
Joe VanAndel
National Center for Atmospheric Research
http://www.atd.ucar.edu/~vanandel/
Internet: vanandel at ucar.edu
More information about the NumPy-Discussion
mailing list