【发布时间】:2016-02-17 15:25:56
【问题描述】:
我正在学习 python,想知道下面的代码在 Python 中做了什么:
def inter_lin_nan(ts, rule):
ts = ts.resample(rule)
mask = np.isnan(ts)
ts[mask] = np.interp(np.flatnonzero(mask), np.flatnonzero(~mask), ts[~mask])
return(ts)
我知道这是一个对时间序列数据进行插值的函数,第二行根据规则(例如 1 小时)重新采样数据。第四行和第五行呢?这种插值是如何完成的? np.interp 需要什么价值,~mask 是什么?
【问题讨论】:
-
np可能是 numpy 模块,您可以查看它的文档(docs.scipy.org/doc,对于interpdoc docs.scipy.org/doc/numpy/reference/generated/numpy.interp.html)。关于mask,应该在你的代码里,请加进去让我们看看是什么 -
是的,np 是 numpy,但你可以看到
mask=np.isnan(ts)
标签: python numpy interpolation nan