[Numpy-discussion] Questions about masked arrays

Pierre GM pgmdevlist at gmail.com
Tue Oct 6 22:06:28 EDT 2009


On Oct 6, 2009, at 6:57 PM, Gökhan Sever wrote:
>
> Seeing a different filling value is causing confusion. Both for  
> myself, and when I try to demonstrate the usage of masked array to  
> other people. Also say, if I want to replace that one element back  
> to its original state will it use fill_value as 1e+20 or 999999.9999?

I knew I was missing something:

When you use display a mask entry, you actually display the `masked`  
constant: it's a 0-shaped float masked array with its own  
`fill_value`, but more importantly, it's a constant. You can use it to  
test whether one element is masked. Check this example:
 >>> x = ma.array([1,2,3],mask=[0,1,0],dtype=int,fill_value=999)
 >>> x
masked_array(data = [1 -- 3],
              mask = [False  True False],
        fill_value = 999)
 >>> x[1] is masked
True
 >>> x[1]
masked_array(data = --,
              mask = True,
        fill_value = 1e+20)

Now, you can change the fill_value of the masked element to whatever  
you want, but it'll be propagated
 >>> ma.masked.fill_value = -999.
 >>> x[1]
masked_array(data = --,
              mask = True,
        fill_value = -999.0)
 >>> y = ma.array([3,2,1],mask=[1,0,1])
 >>> y[0]
masked_array(data = --,
              mask = True,
        fill_value = -999.0)

See ?

Now, I understand this behavior is a bit confusing. Unfortunately, we  
need to keep being able to use (element is masked), which implies that  
we need to keep this apparent inconsistency.
What we could do is to define some specific display for the `masked`  
constant like `masked`. I'm open to suggestions.




More information about the NumPy-Discussion mailing list