-
-
Notifications
You must be signed in to change notification settings - Fork 10.9k
Operation on masked_array changes fill_value #3762
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
A similar thing happens with the take operation in numpy 1.7 ... np.version.version Looks like the same thing would happen in numpy 1.8 |
Sounds like something reasonable to do. |
A related question popped up on SO today: http://stackoverflow.com/q/35324836/1461210 In versions >= 1.10.0: x = np.random.randn(10, 10)
m = np.ma.masked_array(x, x < 0.5, fill_value=1)
print((m * m).fill_value)
# 1e+20
print(np.multiply(m, m).fill_value)
# 1.0 Prior to 1.10.0 I get a fill value of 1.0 in both cases, which seems much more reasonable to me. The behaviour in question was introduced in 3c6b6ba. |
Probably related: #7122. |
It looks like most (all) of the reductions operations do not preserve the
This could be fixed (and I'm willing to submit a PR) but explicitly setting the fill value of the returned array in the various MaskedArray methods. Is this the desired behavior, or should the current behavior of using the default fill_value for these arrays be maintained? |
Some related problem with the multiplication with a scalar: some example test code: import numpy as np
h = np.array([0.0,2,3.2,4.5])
print("h: {}".format(h))
for fill_value in [float("inf"), 1e20, 0]:
print("\ntesting with fill_value={}".format(fill_value))
hma=np.ma.masked_array(h, [True, False, True, False], fill_value=fill_value)
print("hma: {}".format(hma.__repr__()))
print("np.asarray(hma)): {}".format(np.asarray(hma)))
print("1.0 * hmat: {}".format((1.0 * hma).__repr__()))
print("np.asarray(1.0 * hma)): {}".format(np.asarray(1.0 * hma))) And the output for the fill_value 0 :
the fill'_value doesn't change. according to System informations: numpy: 1.16.0 |
I first raised this issue on stackoverflow (see link on the bottom)
Seems like the new masked_array should inherit the fill_value from the two masked_arrays being summed?
Can someone explain to me this behavior of a numpy masked_array? It seems to change the fill_value after applying the sum operation, which is confusing if you intend to use the filled result.
Prints output:
http://stackoverflow.com/questions/18879272/why-does-sum-operation-on-numpy-masked-array-change-fill-value-to-1e20
The text was updated successfully, but these errors were encountered: