import numpy as np
from scipy.interpolate import interp1d
x = np.array([ 0, 0, 0, 0, 0, 30])
time = np.array([ 5, 5, 10, 10, 10, 20])
intx = interp1d(time,x,'linear', 0, True, False, 0)
print intx([4,5,5,6,10,11,20, 20.0001])
>>> [ 0. nan nan 0. 0. 3. 30. 0.]
Run Code Online (Sandbox Code Playgroud)
如您所见,除了时间值==第一对值之外的所有情况下,插值返回实数.
我知道numpy.unique(),这只是一个学术问题.这是在iPython中运行的Anaconda Python 2.7.
谢谢!