[Numpy-discussion] Question about masked arrays
Mon Sep 20 16:09:52 CDT 2010
On Mon, Sep 20, 2010 at 4:03 PM, Gökhan Sever <email@example.com> wrote:
> On Mon, Sep 20, 2010 at 3:34 PM, Benjamin Root <firstname.lastname@example.org> wrote:
>> I have been using masked arrays quite extensively. My take on them is
>> that if a masked array makes sense in that operation, then they should still
>> work with the regular functions. However, there have been many cases where
>> a developer used np.asarray() instead of np.asanyarray() for their code,
>> which causes the masked array object to lose the mask. If you encounter
>> such situations, it is usually a bug and should be reported.
> Do you think then in my case assigning the masked array to np.zeros and
> getting a non-masked return is a bug or I should make sure that I am
> providing a masked array equivalent zeros function before I start
> doing computation?
If you have any variable and you assign np.zeros() to it, then whatever was
there previously is replaced. If you want to create a masked array, then
use np.ma.zeros(), or take an array and put it through np.ma.masked_array()
with the mask keyword to create the mask at the same time. Note that this
approach supposedly uses the original array, so you aren't paying much of a
> And also if the inner execution could be clarified by asanyarray assertion
> why there is ma equivalent array operation functions?
That is a design question for the numpy gods...
>> Actually, that reminds me... watch out for np.polyfit() with masked
>> arrays. It doesn't behave quite nicely with masked arrays and the results
>> are deceptive. It may appear to be right, but it is not. Use
> Hah, you should see my scipy.optimize.leastsq in action. I estimate
> geometric mean and standard deviation parameters for log-normal aerosol
> population. It runs, with the values masked and unmasked (from above
> np.zeros and np.ma.zeros difference) but resulting all kind interesting
I wonder if the functions were originally intended to work with masked
arrays, but at some point, some inner part of the algorithm became
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the NumPy-Discussion