[Numpy-discussion] Thoughts on masked arrays

Michael Haggerty mhagger at alum.mit.edu
Fri May 11 14:31:58 EDT 2001

"Paul F. Dubois" <paul at pfdubois.com> writes:
> The method __array__(self, typecode=None) is a special (existing)
> hook for conversion to a Numeric array. Many operations in Numeric,
> when presented with an object x to be operated upon, such as
> Numeric.sqrt(x), will call x.__array__ as a final act of desperation
> in an attempt to convert their argument to a Numeric
> array. Heretofore it was essentially returning x.filled(). This
> bothered me, because it was a silent conversion that replaced masked
> values with the fill value.

This bothered me too.

> Solution:
> a. Add a method 'unmask()' which will replace the mask by None if
> possible.  It will not fail.
> b. Change MaskedArray.__array__ to work as follows:
>    a. self.unmask(), and then
>    b. Return the raw data if the mask is now None.
>       Otherwise, throw an MAError.

Perfect.  Great solution!


Michael Haggerty
mhagger at alum.mit.edu

More information about the NumPy-Discussion mailing list