1 回答

TA貢獻1802條經驗 獲得超6個贊
哪個插值是指'next'?通常默認是線性的。有一個 numpy 等價物嗎?
插值方法'next'插值到數據集中的下一個數據點(參見:https ://www.mathworks.com/help/matlab/ref/interp1.html )。
查看 NumPy 的文檔 ( https://numpy.org/doc/stable/reference/generated/numpy.interp.html ),看起來好像他們使用線性插值,所以如果你想要相同的輸出,你只需要指定這在您的 MATLAB 命令中,如下所示:
interp1(TMP.time_hor, TMP.lane_hor, TMP.travel_time, 'linear')
話雖如此,'linear'是 的默認插值方法interp1,因此您也可以簡單地忽略該參數并使用命令:
interp1(TMP.time_hor, TMP.lane_hor, TMP.travel_time)
我希望這有幫助!
編輯:我剛剛意識到你要問的是向后你想使用 Python 中的 'next' 方法進行插值。我是這樣做的:
import numpy as np
import scipy as sp
# Generate data
x = np.linspace(0, 1, 10)
y = np.exp(x)
# Create interpolation function
f = sp.interpolate.interp1d(x, y, 'next')
# Create resampled range
x_resampled = np.linspace(x[0], x[-1], 100)
# Here's your interpolated data
y_interpolated = f(x_resampled)
添加回答
舉報