使用scipy.interpolate.interp1d
进行线性插值时,我遇到以下行为:
from scipy.interpolate import interp1d
import numpy as np
x = [0,1,2,3,4]
y = [np.inf, 10, 12, 11, 9]
interpolated_function = interp1d(x,y)
当然,插值在[0,1)
中没有很好地定义,但是在1
中,我希望它被定义。但是:
这是预期的行为吗?在1
处的插值函数不应该求值为10
,因为这是传递给interp1d
的完全有效的数据点吗?在
interp1d
不是特殊情况nan
s或inf
s。对于kind="linear"
,它只是在包含输入值的时间间隔内使用错误消息中打印的公式。在由于精确相等在浮点中不可靠,通过在
1.0
处求值,您依赖于将其分类为(0,1)或(1,2)的实现细节。在例如
在scipy的未来版本中,行为将取决于
fill_value
。(在当前的开发版本中,您可以使用fill_value="extrapolate"
。)对于非有限的用户来说,过滤掉有限的数字是最好的。在
^{pr2}$相关问题 更多 >
编程相关推荐