在这种简单的插值情况下,
毫无根据的期望。径向基函数插值,顾名思义,使用径向基函数。默认情况下,基函数
sqrt((r/epsilon)**2 + 1)
其中r是到数据点的距离,epsilon是一个正参数。这类函数的加权和不可能是同一常数。RBF插值不像线性或双线性插值。这是一种适用于粗数据的粗插值。
通过设置一个荒谬的大epsilon,您可以接近1;因为它使网格上的基函数几乎相同。
rbfi = Rbf(x_coarse.ravel(), y_coarse.ravel(), data_coarse.ravel(), epsilon=10)
# ...
print(interpolated_data.min(), interpolated_data.max())
# outputs 0.9999983458255883 1.0000002402521204
但是这不是一个好主意,因为当数据
不
常数时,会有太多的长程影响。
只给我1000个插值数据?
那就是线性插值。
LinearNDInterpolator
语法与
Rbf
,因为它返回一个可调用的。
linear = LinearNDInterpolator(np.stack((x_coarse.ravel(), y_coarse.ravel()), axis=-1),
data_coarse.ravel())
interpolated_data = linear(x_fine.ravel(), y_fine.ravel()).reshape([x_fine.shape[0], y_fine.shape[0]])
print(interpolated_data.min(), interpolated_data.max())
# outputs 1.0 1.0
还有一个
griddata
有更多的插值模式。