On June 11, 2013 at 00:40:31, Pierre GM ([email protected]) wrote: On June 10, 2013 at 23:07:24 , Eric Firing ([email protected]) wrote: On 2013/06/10 10:17 AM, Aldcroft, Thomas wrote: > I use np.ma <http://np.ma>, and for me the most intuitive would be the > second option where the new array matches the original array in shape > and dtype, but always has an empty mask. I always think of the *_like() > functions as just copying shape and dtype, so it would be a bit > surprising to get part of the data (the mask) from the original. If you > do need the mask then on the next line you have an explicit statement to > copy the mask and the code and intent will be clear. Also, most of the > time the mask is set because that particular data value was bad or > missing, so it seems like it would be a less-common use case to want a > new empty array with the same mask. >
I also use np.ma (and it is used internally in matplotlib). I agree with Tom. I think all of the *_like() functions should start with mask=False, meaning nothing is masked by default. I don't see what the reasonable use cases would be for any alternative.
Thinking about it, a replacement to `_convert2ma` should work something like `func(input.view(np.ndarray)).view(np.ma.MaskedArray)`
The `input.view(np.ndarray)` will get the `.data` part of a MaskedArray and work seamlessly with a regular ndarray, the `.view(MaskedArray)` will attach a `np.ma.nomask` to the result of the previous view (therefore making the output a MaskedArray). Depending on your decision, we could add a flag to copy the initial mask (if any) |
_______________________________________________
NumPy-Discussion mailing list
[email protected]
http://mail.scipy.org/mailman/listinfo/numpy-discussion