[Numpy-discussion] empty_like for masked arrays

Eric Firing efiring@hawaii....
Mon Jun 10 16:07:14 CDT 2013


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.

Eric


More information about the NumPy-Discussion mailing list