<html><head></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><p id="bloop_customfont" style="margin: 0px; "><span style="color: rgb(160, 160, 168); font-size: 12px;"><font face="Monaco">On June 11, 2013 at 00:40:31, Pierre GM (pgmdevlist@gmail.com) wrote:</font></span></p> <div><blockquote type="cite" style="color: rgb(0, 0, 0); font-variant: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255); border-left-style: solid; border-width: 1px; margin-left: 0px; padding-left: 10px; "><span style="font-size: 12px;"><div><font face="Monaco">On June 10, 2013 at 23:07:24 , Eric Firing (efiring@hawaii.edu) wrote:<span class="Apple-converted-space"> </span><br>On 2013/06/10 10:17 AM, Aldcroft, Thomas wrote:<span class="Apple-converted-space"> </span><br>> I use np.ma <http://np.ma>, and for me the most intuitive would be the<span class="Apple-converted-space"> </span><br>> second option where the new array matches the original array in shape<span class="Apple-converted-space"> </span><br>> and dtype, but always has an empty mask. I always think of the *_like()<span class="Apple-converted-space"> </span><br>> functions as just copying shape and dtype, so it would be a bit<span class="Apple-converted-space"> </span><br>> surprising to get part of the data (the mask) from the original. If you<span class="Apple-converted-space"> </span><br>> do need the mask then on the next line you have an explicit statement to<span class="Apple-converted-space"> </span><br>> copy the mask and the code and intent will be clear. Also, most of the<span class="Apple-converted-space"> </span><br>> time the mask is set because that particular data value was bad or<span class="Apple-converted-space"> </span><br>> missing, so it seems like it would be a less-common use case to want a<span class="Apple-converted-space"> </span><br>> new empty array with the same mask.<span class="Apple-converted-space"> </span><br>><span class="Apple-converted-space"> </span><br><br>I also use np.ma (and it is used internally in matplotlib). I agree<span class="Apple-converted-space"> </span><br>with Tom. I think all of the *_like() functions should start with<span class="Apple-converted-space"> </span><br>mask=False, meaning nothing is masked by default. I don't see what the<span class="Apple-converted-space"> </span><br>reasonable use cases would be for any alternative.<span class="Apple-converted-space"> </span><br><br></font></div></span></blockquote></div><p><font face="Monaco"><span style="font-size: 12px;"><br></span></font></p><p><font face="Monaco"><span style="font-size: 12px;">Thinking about it, a replacement to `_convert2ma` should work something like</span></font></p><p><font face="Monaco"><span style="font-size: 12px;">`func(input.view(np.ndarray)).view(np.ma.MaskedArray)`</span></font></p><p><font face="Monaco"><span style="font-size: 12px;"><br></span></font></p><p><font face="Monaco"><span style="font-size: 12px;">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)</span></font></p><div></div></body></html>