[Numpy-discussion] Unexpected behaviour by in place addition of array and masked array
Hanno Klemm
klemm at phys.ethz.ch
Thu Apr 24 05:35:41 EDT 2008
Hi,
I tried adding a masked array and a usual array in place and got back
the usual array. Is this expected behaviour? I would have expected to
get a masked array back.
The below example illustrates what I mean.
>>> import numpy as N
>>> a = N.zeros((3,3), dtype=float)
>>> b = N.ma.MaskedArray([[1,2,3],[2,3,4],[4,5,6]], mask =
[[0,0,0],[1,0,1], [0,0,0]])
>>> b
array(data =
[[ 1 2 3]
[999999 3 999999]
[ 4 5 6]],
mask =
[[False False False]
[ True False True]
[False False False]],
fill_value=999999)
>>> a+b
array(data =
[[ 1.00000000e+00 2.00000000e+00 3.00000000e+00]
[ 1.00000000e+20 3.00000000e+00 1.00000000e+20]
[ 4.00000000e+00 5.00000000e+00 6.00000000e+00]],
mask =
[[False False False]
[ True False True]
[False False False]],
fill_value=1e+20)
>>> a+=b
>>> a
array([[ 1., 2., 3.],
[ 0., 3., 0.],
[ 4., 5., 6.]])
>>> N.__version__
'1.0.4'
>>>
Best regards,
Hanno
--
Hanno Klemm
klemm at phys.ethz.ch
More information about the NumPy-Discussion
mailing list