<div dir="ltr"><br><div class="gmail_extra"><br><br><div class="gmail_quote">On Mon, Jun 10, 2013 at 3:47 PM, Nathaniel Smith <span dir="ltr"><<a href="mailto:njs@pobox.com" target="_blank">njs@pobox.com</a>></span> wrote:<br>

<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">Hi all,<br>
<br>
Is there anyone out there using numpy masked arrays, who has an<br>
opinion on how empty_like (and its friends ones_like, zeros_like)<br>
should handle the mask?<br>
<br>
Right now apparently if you call np.ma.empty_like on a masked array,<br>
you get a new masked array that shares the original array's mask, so<br>
modifying one modifies the other. That's almost certainly wrong. This<br>
PR:<br>
  <a href="https://github.com/numpy/numpy/pull/3404" target="_blank">https://github.com/numpy/numpy/pull/3404</a><br>
makes it so instead the new array has values that are all set to<br>
empty/zero/one, and a mask which is set to match the input array's<br>
mask (so whenever something was masked in the original array, the<br>
empty/zero/one in that place is also masked). We don't know if this is<br>
the desired behaviour for these functions, though. Maybe it's more<br>
intuitive for the new array to match the original array in shape and<br>
dtype, but to always have an empty mask. Or maybe not. None of us<br>
really use <a href="http://np.ma" target="_blank">np.ma</a>, so if you do and have an opinion then please speak<br>
up...<br></blockquote><div><br></div><div>I use <a href="http://np.ma">np.ma</a>, 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.</div>

<div><br></div><div>My 2c,</div><div>Tom</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">


<br>
-n<br>
_______________________________________________<br>
NumPy-Discussion mailing list<br>
<a href="mailto:NumPy-Discussion@scipy.org">NumPy-Discussion@scipy.org</a><br>
<a href="http://mail.scipy.org/mailman/listinfo/numpy-discussion" target="_blank">http://mail.scipy.org/mailman/listinfo/numpy-discussion</a><br>
</blockquote></div><br></div></div>