[Numpy-discussion] bug with with fill_values in masked arrays?
Wed Mar 26 14:42:41 CDT 2008
Pierre GM wrote:
> My bad, I neglected an overall doc for the functions and their docstring. But
> you know what ? As you're now at an intermediary level,
That's pretty unkind to your userbase. I know a lot about python, but
I'm a total novice with numpy and even the maths it's based on.
> help: just write down the problems you encountered, and the solutions you
> came up with, so that we could use your experience as the backbone for a
> proper MaskedArray documentation
Blind leading the blind seems like a terrible idea to me...
> Try that:
>>>> x = numpy.ma.array([0,1,2,3,])
>>>> x[-1] = numpy.nan
>>>> print x
>>>> [0 1 2 0]
> See? No NaNs with an int array.
Right. "Array types" and whatever a dtype is are things that could be
much better documented too :-(
> Well, no problem, they should stick around. Note that if a NaN/Inf should
> normally show up as the result of some operation (divide by zero for
> example), it'll probably won't:
>>>> x = numpy.ma.array([0,1,2,numpy.nan],dtype=float)
>>>> print 1./x
>>>> [-- 1.0 0.5 nan]
NaN/inf is still NaN in my books, so why would I be surprised by this?
>> I'd argue that the masked singleton having a different fill value to the
>> ma it comes from is a bug.
> "It's not a bug, it's a feature"TM
One which sucks and is unintuitive.
> The fill_value for the mask singleton is meaningless, correct. However, having
> numpy.ma.masked as a constant is really helpful to test whether a particular
> value is masked, or to mask a particular value:
>>>> x = numpy.ma.array([0,1,2,3])
>>>> x[-1] = masked
>>>> x[-1] is masked
I may not know much about maths, but I know about these funny things in
python we have called "classes" to solve exactly this problem ;-)
>>> x[-1] = Masked(fill_value=50)
...which gives you what you want without forcing me to experience the
Simplistix - Content Management, Zope & Python Consulting
More information about the Numpy-discussion