[Numpy-discussion] MaskedArray and the min, max, sum, prod Methods

Pierre GM pgmdevlist at gmail.com
Fri Jan 4 15:20:11 EST 2008


On Friday 04 January 2008 12:01:14 Alexander Michael wrote:
> Concretely, this is how I would write my own prod function:
>
> def ma_prod(a):
>     p = 1.0
>     for x in a.data[~a.mask]:
>         p *= x
>     return p

Which would work only in 1D, as you mentioned.

> All the CS mumbo-jumbo aside, the real question appears to be are fully
> masked arrays empty or undefined? I would consider them conceptually empty,
> if only because it makes for a convenient continuity as the number of
> masked elements increases from one to the whole of the array.

That's a way to see it. Personally, I'm happy with this behavior: getting 
masked as the result of .sum() tells me that all the initial values were 
masked, which is not the same thing as getting 0.

> Thanks for the hard work on the new MaskedArray. I'm attempting to be
> constructive by raising these issues, so please let me know if my comments
> are otherwise.

Oh please, thanks a lot for your contributions ! Another issue is that we need 
to ensure compatibility with the previous version of maskedarray 
(numpy.core.ma). At the end, that's what matters.



More information about the NumPy-Discussion mailing list