You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When a np.array (say a) is added with np.ma.masked_array (say ma) using a += ma operator, it gives a np.array output while a = a + ma gives a np.ma.maked_array output.
I expected a masked array as an output for a += ma but I guess the implementation always outputs the same object when operated in-place. Technically, there is no issue there as += is in-place operator and so an np.ndarray remains np.ndarray. Can this still be made a new feature though? I am not sure so feel free to close this :)
It seems like you've very nicely answered your own question. Generally, __array_priority__ is used to determine the output type of operations (higher array_priority wins). E.g. for masked arrays:
In-place operations get a bit hairy though, as the behavior is generally ill-defined. For example:
>>>m=np.ma.arange(10)
>>>m.mask= [True]*5+ [False]*5>>>a+=m# What do you expect
You might (reasonably) expect a = array([ 0, 1, 2, 3, 4, 10, 12, 14, 16, 18]), i.e. the output type is ndarray, but the mask from m was respected in the operation. This is currently not the case. The behavior could be changed, but this would require a larger discussion. See e.g. this discussion if you are interested.
I think the original question was sufficiently answered, so I will close this - feel free to re-open or start/join an existing discussion if you are interested in some of these details.
When a
np.array
(saya
) is added withnp.ma.masked_array
(sayma
) usinga += ma
operator, it gives anp.array
output whilea = a + ma
gives anp.ma.maked_array
output.Reproducing code example:
Error message:
Numpy/Python version information:
The text was updated successfully, but these errors were encountered: