-
-
Notifications
You must be signed in to change notification settings - Fork 10.9k
ma.empty_like copies reference to mask instead of making a new mask #3145
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
Any progress? As noted in #2572, By the way, I use a below snippet to circumvent this issue. # b = numpy.zeros_like(a)
b = a.copy()
b.fill(0) |
No progress - it's a nasty bug but probably the only person who it's urgent
|
As underlying `empty_like()` knows nothing about mask, it would be `_convert2ma`'s job to properly set up the output mask. `copy` argument is added to figure out which functions need this behavior. `ones_like()` and `zeros_like()` which were mere aliases of regular numpy functions now go through `_convert2ma` as well. Hopefully this fixes numpy#3145, numpy#2572.
Well, a5a3457 forces |
Please submit a PR - that's the standard interface we use for reviewing
|
@jjhelmus: Thanks! |
ma.empty_like on a masked array creates a new masked array with the mask pointing to the same mask as the source array, so if the target array mask is changed, the mask of the source array changes as well. Code sample:
from numpy import * # create some random data a = random.random((5,5)) # make this a masked array a = ma.masked_greater(a, 0.3) # use empty_like to create a new array b = ma.empty_like(a) # change b, in particular do something that sets the mask to False b[:,:] = 2.0 # check whether at least one element in a is still masked print a.mask.any()
You will see that this destroys the mask of a. Note that this issue is similar to #2572, except that this exists even for numpy.ma.empty_like, which, being from the numpy.ma module, should in principle know how to handle masked arrays.
The text was updated successfully, but these errors were encountered: