[Numpy-discussion] Numpy Nu-bee: "forward fill" function

Joshua Ford jqford@hotmail....
Tue Sep 30 07:20:08 CDT 2008


Thank you so very much!




> From: pgmdevlist@gmail.com
> To: numpy-discussion@scipy.org
> Date: Mon, 29 Sep 2008 23:24:02 -0400
> Subject: Re: [Numpy-discussion] Numpy Nu-bee: "forward fill" function
> 
> On Monday 29 September 2008 22:31:47 Joshua Ford wrote:
> > I would like to conduct the equivalent of a "forward fill" function on an
> > array, that repeats the last non-null value until the next non-null value
> > is reached.  I saw that the scipy TimeSeries  has a "forward_fill"
> > function:
> >
> > http://pytseries.sourceforge.net/lib/interpolation.html
> >
> > I would like to do exactly what the TimeSeries "forward_fill" function does
> > - but I don't have a time series.
> 
> Which is quite OK, because you don't need a time series, a simple MaskedArray 
> will do. For your example
> 
> >>> import numpy.ma as ma
> >>> import scikits.timeseries.lib as tl
> >>> a= ma.masked_values(([1,2,3,4,5,6,-999,-999,-999,-999,7,8], -999)
> >>> a
> masked_array(data = [1 2 3 4 5 6 -- -- -- -- 7 8],
>       mask = [False False False False False False  True  True  True  True 
> False False],
>       fill_value=-999)
> >>> tl.forward_fill(tl)
> masked_array(data = [1 2 3 4 5 6 6 6 6 6 7 8],
>       mask = [False False False False False False False False False False 
> False False],
>       fill_value=-999)
> 
> _______________________________________________
> Numpy-discussion mailing list
> Numpy-discussion@scipy.org
> http://projects.scipy.org/mailman/listinfo/numpy-discussion
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://projects.scipy.org/pipermail/numpy-discussion/attachments/20080930/17f18a39/attachment.html 


More information about the Numpy-discussion mailing list