def nan_interp(y, silent=False):
"""
Return a new array with nans found in *y* filled with linear
interpolants.
"""
# Source: http://stackoverflow.com/questions/6518811/interpolate-nan-values-in-a-numpy-array
nans, x = nan_helper(y)
z = NP.array(y)
if not silent and sum(nans) > 0:
logger.warning('linear interpolation over {} NaN values'.format(sum(nans)))
z[nans]= NP.interp(x(nans), x(~nans), z[~nans])
return z
评论列表
文章目录