[Numpy-discussion] ndarray.fill and ma.array.filled
ndarray at mac.com
Wed Mar 22 13:43:04 CST 2006
In an ideal world, any function that accepts ndarray would accept
ma.array and vice versa. Moreover, if the ma.array has no masked
elements and the same data as ndarray, the result should be the same.
Obviously current implementation falls short of this goal, but there
is one feature that seems to make this goal unachievable.
This feature is the "filled" method of ma.array. Pydoc for this
method reports the following:
| filled(self, fill_value=None)
| A numeric array with masked values filled. If fill_value is None,
| use self.fill_value().
| If mask is nomask, copy data only if not contiguous.
| Result is always a contiguous, numeric array.
| # Is contiguous really necessary now?
That is not the best possible description ("filled" is "filled"), but
the essence is that the result of a.filled(value) is a contiguous
ndarray obtained from the masked array by copying non-masked elements
and using value for masked values.
I would like to propose to add a "filled" method to ndarray. I see
several possibilities and would like to hear your opinion:
1. Make filled simply return self.
2. Make filled return a contiguous copy.
3. Make filled replace nans with the fill_value if array is of
floating point type.
Unfortunately, adding "filled" will result is a rather confusing
situation where "fill" and "filled" both exist and have very different
I would like to note that "fill" is a somewhat odd ndarray method.
AFAICT, it is the only non-special method that mutates the array. It
appears to be just a performance trick: the same result can be achived
with "a[...] = ".
More information about the Numpy-discussion