[Numpy-discussion] difference between ma.masked and ma.masked_array?

Pierre GM pgmdevlist@gmail....
Tue Nov 18 08:53:31 CST 2008


All,

ma.masked_array is a constructor function for ma.MaskedArray, like  
np.array is a constructor for np.ndarray. Its intended use is:
a = ma.masked_array(yourdata, mask=yourmask, dtype=yourdtype)
to which you can add the keyword arguments presented in the doc.

ma.masked is a special constant used to check whether one particular  
value of your array is masked, or to mask one particular value. Note  
that setting a value of an array `x` to `ma.masked` will only work if  
`x` is a MaskedArray, otherwise the value will be set to zero (if the  
array is not a MaskedArray or a child of, there's no mask to modify...)




On Nov 18, 2008, at 12:39 AM, Scott Sinclair wrote:

> 2008/11/17 Timmie <timmichelsen@gmx-topmail.de>:
>
>> I am using this expression along with the scikit.timeseries:
>>
>> series[(series.years>2000)&(series.years<2010)]=np.ma.masked
>>
>> => but now, my series does not get masked.

???
Please provide a self-contained example, so that I can check whether  
it's a bug or not.
On my machine, the following works:
 >>> import numpy as np, numpy.ma as ma, scikits.timeseries as ts
 >>> series =  ts.time_series(np.random.rand(10),  
start_date=ts.Date('A',year=2000))
 >>> series
timeseries([ 0.79956673  0.26526638  0.38811214  0.2119525    
0.55870333  0.73263595
   0.24395387  0.35595176  0.86357901  0.48562605],
            dates = [2000 ... 2009],
            freq  = A-DEC)

Now, let's mask the values after 2005 (included)

 >>> series[series.years>2004] = ma.masked
 >>> series
timeseries([0.799566726537 0.265266376704 0.388112137692  
0.211952497171 0.558703334124
  -- -- -- -- --],
            dates = [2000 ... 2009],
            freq  = A-DEC)

>
> There's some in progress documentation in the Numpy doc app at
> http://docs.scipy.org/numpy/docs/numpy.ma.core.masked_where/ that
> hasn't yet made it's way to the reference manual
> http://docs.scipy.org/doc/numpy/reference/

I know I'm a tad lagging here documentation-wise... Any help welcome.


More information about the Numpy-discussion mailing list