我很难精确地使用scipy.interpolate.RegularGridInterpolant.More,我不能用输出的内插函数进行外推。在文档中,如果“填充值”为0,则将网格外的值外推,但它似乎不起作用。我想要线性地插值,我看到其他函数外推,但使用其他方法(最近的邻居,或一个预定义的值)。
下面是一个使用虚拟数据的示例(不是我工作的数组,但情况是相同的)
import numpy as np
from scipy.interpolate import RegularGridInterpolator
x = np.array([11,22,33,44,55,66,77])
y = np.array([101,102,103,104,105,106,107])
z = np.random.rand(7,7)
x_new = np.array([1,12,23,34,45,56,67])
y_new = np.array([101,102,103,104,105,106,107])
interpolant_function = RegularGridInterpolator((x,y),z, fill_value = None)
result = interpolant_function((x_new,y_new))
此代码引发以下错误
raise ValueError("One of the requested xi is out of bounds "
ValueError: One of the requested xi is out of bounds in dimension 0
我从几天开始就被困住了,而且如果有人知道还有别的功能可以做,而且工作得很好,我很高兴听到你这么做。
发布于 2022-05-04 00:04:51
我想你应该加上“bounds_error=False”。
interpolant_function = RegularGridInterpolator((x,y),z, bounds_error=False, fill_value = None)
https://stackoverflow.com/questions/72103665
复制相似问题