difference between ma.masked and ma.masked_array?
Hello, what is the difference between ma.masked and ma.masked_array? 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. Rather the selected values (left part of the '=') get set to 0.0. But if I use arr_masked = \ ma.masked_array(series, series[(series.years>2000)&(series.years<2010)]) the masked is applied sucessfully. This is very strange. for some examples it works to use the firt method, for others not. Any hint is appreciated. Thanks in advance, Timmie
2008/11/17 Timmie <timmichelsen@gmx-topmail.de>:
what is the difference between ma.masked and ma.masked_array?
I don't know the answer to that question, but both appear to be some kind of alias for the MaskedArray class and not part of the API.
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.
Rather the selected values (left part of the '=') get set to 0.0.
But if I use
arr_masked = \ ma.masked_array(series, series[(series.years>2000)&(series.years<2010)])
the masked is applied sucessfully.
I think you should get the effect you want using masked_where
import numpy.ma as ma masked_series = ma.masked_where((series.years>2000) & (series.years<2010), series)
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/ Cheers, Scott
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.
Hi, My numpy is 1.2.1 and python is 2.5.2. In python, I did: from numpy import * x=array([1,2,3]) z=x.fill(x) print z None z should be filled with zero. I do not knwo why I got None. Can anyone help me on this? Thanks Frank _________________________________________________________________ Proud to be a PC? Show the world. Download the “I’m a PC” Messenger themepack now. hthttp://clk.atdmt.com/MRT/go/119642558/direct/01/
From the docstring:
a.fill(value) -> None. Fill the array with the scalar value. The method modifies the array, but does not return it. Matthieu 2008/11/18 frank wang <f.yw@hotmail.com>:
Hi,
My numpy is 1.2.1 and python is 2.5.2.
In python, I did:
from numpy import * x=array([1,2,3]) z=x.fill(x) print z None
z should be filled with zero. I do not knwo why I got None. Can anyone help me on this?
Thanks
Frank
________________________________ Proud to be a PC? Show the world. Download the "I'm a PC" Messenger themepack now. Download now. _______________________________________________ Numpy-discussion mailing list Numpy-discussion@scipy.org http://projects.scipy.org/mailman/listinfo/numpy-discussion
-- Information System Engineer, Ph.D. Website: http://matthieu-brucher.developpez.com/ Blogs: http://matt.eifelle.com and http://blog.developpez.com/?blog=92 LinkedIn: http://www.linkedin.com/in/matthieubrucher
Thanks for the quick reply. It is my fault to overlook the manual. Frank> Date: Tue, 18 Nov 2008 19:36:23 +0100> From: matthieu.brucher@gmail.com> To: numpy-discussion@scipy.org> Subject: Re: [Numpy-discussion] fill() function does not work.> > >From the docstring:> > a.fill(value) -> None. Fill the array with the scalar value.> > The method modifies the array, but does not return it.> > Matthieu> > 2008/11/18 frank wang <f.yw@hotmail.com>:> > Hi,> >> > My numpy is 1.2.1 and python is 2.5.2.> >> > In python, I did:> >> > from numpy import *> > x=array([1,2,3])> > z=x.fill(x)> > print z> > None> >> > z should be filled with zero. I do not knwo why I got None. Can anyone help> > me on this?> >> > Thanks> >> > Frank> >> > ________________________________> > Proud to be a PC? Show the world. Download the "I'm a PC" Messenger> > themepack now. Download now.> > _______________________________________________> > Numpy-discussion mailing list> > Numpy-discussion@scipy.org> > http://projects.scipy.org/mailman/listinfo/numpy-discussion> >> >> > > > -- > Information System Engineer, Ph.D.> Website: http://matthieu-brucher.developpez.com/> Blogs: http://matt.eifelle.com and http://blog.developpez.com/?blog=92> LinkedIn: http://www.linkedin.com/in/matthieubrucher> _______________________________________________> Numpy-discussion mailing list> Numpy-discussion@scipy.org> http://projects.scipy.org/mailman/listinfo/numpy-discussion _________________________________________________________________ Access your email online and on the go with Windows Live Hotmail. http://windowslive.com/Explore/Hotmail?ocid=TXT_TAGLM_WL_hotmail_acq_access_...
---------- Forwarded message ---------- From: Matthieu Brucher <matthieu.brucher@gmail.com> Date: Tue, Nov 18, 2008 at 1:36 PM Subject: Re: [Numpy-discussion] fill() function does not work. To: Discussion of Numerical Python <numpy-discussion@scipy.org>
From the docstring:
a.fill(value) -> None. Fill the array with the scalar value. The method modifies the array, but does not return it. Matthieu 2008/11/18 frank wang <f.yw@hotmail.com>:
Hi,
My numpy is 1.2.1 and python is 2.5.2.
In python, I did:
from numpy import * x=array([1,2,3]) z=x.fill(x) print z None
z should be filled with zero. I do not knwo why I got None. Can anyone help me on this?
Thanks
Frank
________________________________ Proud to be a PC? Show the world. Download the "I'm a PC" Messenger themepack now. Download now. _______________________________________________ Numpy-discussion mailing list Numpy-discussion@scipy.org http://projects.scipy.org/mailman/listinfo/numpy-discussion
-- Information System Engineer, Ph.D. Website: http://matthieu-brucher.developpez.com/ Blogs: http://matt.eifelle.com and http://blog.developpez.com/?blog=92 LinkedIn: http://www.linkedin.com/in/matthieubrucher _______________________________________________ Numpy-discussion mailing list Numpy-discussion@scipy.org http://projects.scipy.org/mailman/listinfo/numpy-discussion For additional clarity: you write x.fill(x), but this is not what you want because this would take the first entry in x and fill the remainder of x with it. Instead, you want x.fill(0). Alternately, the function zeros is useful. -Frank
participants (6)
-
Frank Lagor
-
frank wang
-
Matthieu Brucher
-
Pierre GM
-
Scott Sinclair
-
Timmie