在二维网格上使用numpy/scipy进行插值 [英] Interpolation with numpy/scipy on 2-D grid
本文介绍了在二维网格上使用numpy/scipy进行插值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
例如:
让我们考虑点为x=(2,2)
.然后考虑一个4网格邻域,我们将点x_1=(1,2), x_2=(2,3), x_3=(3,2), x_4=(2,1)
作为x
的邻居.假设在这些点上某些兴趣量的值是y=5, y_1=7, y_2=8, y_3= 10, y_4 = 3
.
通过插值,我想在子像素值(例如(2.7, 2.3)
)处找到y
.
上面的问题可以用numpy数组表示,如下所示.
x = [(2,2), (1,2), (2,3), (3,2), (2,1)]
y = [5,7,8,10,3]
如何使用numpy/scipy插值来做到这一点?我找不到处理它的具体示例.
解决方案
方法 解决方案
The method griddata
is sufficient here. By default it performs piecewise linear interpolation, which in your example seems the most suitable approach.
from scipy.interpolate import griddata
x = [(2,2), (1,2), (2,3), (3,2), (2,1)]
y = [5,7,8,10,3]
evaluate_at = [(2.7, 2.3)] # could be an array of points
result = griddata(x, y, evaluate_at)
Returns array([ 9.4])
.
这篇关于在二维网格上使用numpy/scipy进行插值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文