[Numpy-discussion] Re: ndarray.fill and ma.array.filled

Sasha ndarray at mac.com
Fri Apr 7 10:26:06 CDT 2006

I am posting a reply to my own post in a hope to generate some discussion of
the original proposal.

I am proposing to add a "filled" method to ndarray.  This can be a
pass-through, an alias to "copy" or a method to replace nans or some other
type-specific values.  This will allow code that uses "filled" work on
ndarrays without changes.

On 3/22/06, Sasha <ndarray at mac.com> wrote:
> 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
> meanings.
> 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[...] = ".
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://projects.scipy.org/pipermail/numpy-discussion/attachments/20060407/7b3043bc/attachment.html 

More information about the Numpy-discussion mailing list