[Numpy-discussion] Masked array - follow up

Pierre GM pgmdevlist at mailcan.com
Wed Mar 22 13:58:02 CST 2006

I'm still not sure the `flag_missing` option is really needed. Probably not, 
as you noted. I intended to use it as a reminder, just in case. I agree with 
you, it's confusing and should probably be discarded. that maybe useful a bit 
later, for cumprod for example: we could have something like:
if `use_missing`: 
	a.cumprod() = MA.masked
	a.cumprod() = a.filled(1).cumprod()

> I would think this
> feature is unnecessary because a.fill(0).trace() is a better way to
> express the desired result than a.trace(flag_missing=False). 

If all the elements of the diagonal of a are masked, what should a.trace() 
be ? 0, MA.masked, undefined ? `a.fill(0).trace` (well, `a.filled(0).trace` 
actually)  will always give 0. The version I implemented give you MA.masked. 
try it.

> Your implementation is equivalent to a.data.trace(), which is clearly wrong
> because masked elements are likely to contain garbage.)
Well, not really: if a is a MaskedArray 
d = diagonal(a,offset, axis1, axis2)
outputs a MaskedArray, with d.data=a.diagonal().data and 
d.mask=d.diagonal.mask(). Check it. 
The version implemented actually corresponds to:
a.trace() = a.diagonal().compressed().sum()

> PS: BTW, your implementation is incorrect.  Currently ma assumes that
> "masked" is a singleton, so return MaskedArray(0, int, mask=1) is not
> the same as return masked. 
well, I intended to use masked, but realize `masked` wasn't defined before the 
last line, so I just copied its definition.

> Also m = getmask(a) should probably be m = 
> getmask(d).
Well, no, not really: m is only used to check whether the initial array is 
masked or not.

BTW, I attach the unittest I just finished writing. That passes on my box. Let 
me know how it works
-------------- next part --------------
A non-text attachment was scrubbed...
Name: testnewma.py
Type: application/x-python
Size: 3431 bytes
Desc: not available
Url : http://projects.scipy.org/pipermail/numpy-discussion/attachments/20060322/b8446188/attachment-0001.bin 

More information about the Numpy-discussion mailing list