[Numpy-discussion] Concepts for masked/missing data

Benjamin Root ben.root at ou.edu
Sat Jun 25 14:58:56 EDT 2011


On Sat, Jun 25, 2011 at 12:17 PM, Wes McKinney <wesmckinn at gmail.com> wrote:

>
> Agree. My basic observation about numpy.ma is that it's a finely
> crafted solution for a different set of problems than the ones I have.
> I just don't want the same thing to happen here so I'm stuck writing
> code (like I am now) that looks like
>
> mask = y.mask
> the_sum = y.sum(axis)
> the_count = mask.sum(axis)
> the_sum[the_count == 0] = nan
>
>
Yeah, you are expecting NaN behavior there, in which case, using NaNs
without masks is fine.  But, for a general solution, you might want to
consider that masked_array provides a "recordmask" as well as a mask.
Although, the documentation is very lacking, and using masked arrays with
record arrays seems very clumsy, but that is certainly something that could
get cleaned up.

Also, as a cleaner version of your code:

the_sum = y.sum(axis)
the_sum.mask = np.any(y.mask, axis)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20110625/c631be99/attachment.html>


More information about the NumPy-Discussion mailing list