[Numpy-discussion] Re: ndarray.fill and ma.array.filled
pgmdevlist at mailcan.com
Mon Apr 10 10:58:02 CDT 2006
> If you sum along a particular dimension and encounter a masked value,
> the result is masked.
That's not how it currently works (still on 0.9.6):
MA.masked_where((x%5==0) | (x%3==0),x).sum(0)
array(data = [12 1 2 18],
mask = [False False False False],
and frankly, I'd be quite frustrated if it had to change:
- `filled` is not a ndarray method, which means that a.filled(0).sum() fails
if a is not MA. Right now, I can use a.sum() without having to check the
nature of a first.
- this behavior was already in Numeric
- All my scripts rely on it (but I guess that's my problem)
- The current way reflects how mask are used in GIS or image processing.
> If you would like to ignore masked values, you write
> a.filled(0).sum() instead of a.sum(). In 1d case, you can also use
Once again, Sasha, I'd agree with you if it wasn't a major difference
> In other words, what in R you achieve with a
> flag, such as in sum(a, na.rm=TRUE), in numpy you achieve by an
> explicit call to "fill". This is not quite the same as na.actions in
> R, but that is what I had in mind.
I kinda like the idea of a flag, though
More information about the Numpy-discussion