[Numpy-discussion] Optimize removing nan-values of dataset

David Reed david.reed.c at gmail.com
Wed Aug 14 11:49:32 EDT 2013


Yeah, interp is what you want.  What you want to do with the end values is
up to you, but could be done like this:

ind = where(logical_not(np.isnan(y)))[0]
y1 = interp(range(len(y)), ind, y[ind])
y1 = y1[ind[0]:ind[-1]]


On Wed, Aug 14, 2013 at 4:38 AM, Thomas Goebel <
Thomas.Goebel at th-nuernberg.de> wrote:

> * On 13/08/2013 23:32, David Reed wrote:
> > Hi Thomas,
> >
> > Your array is Nx6 do you want the nan values replace by the
> > mean of the 2 adjacent elemets by row or by column?
>
> Hi David,
>
> i want it to be replaced by column.
>
>
> I also found numpy.interp but this function replaces all nan
> values at the beginning/end of array which should be omitted.
>
> As an example:
> y = np.array([nan, nan, 1, 2, 3, nan, nan, 4, nan, 5, nan, nan])
> nans = np.isnan(y)
>
> Only the values y[5:7] and y[8] should be replaced. Is it
> possible to set nans[0:2] and nans[-2:] to False with something
> like nans.startswith nans.endswith?
> _______________________________________________
> NumPy-Discussion mailing list
> NumPy-Discussion at scipy.org
> http://mail.scipy.org/mailman/listinfo/numpy-discussion
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20130814/c684b336/attachment.html>


More information about the NumPy-Discussion mailing list