我检查了 scipy 中可用的插值方法,但无法找到适合我的情况的正确解决方案。 假设我有 100 个坐标是随机的点, 例如,它们的 x 和 y 位置是:
x=np.random.rand(100)*100
y=np.random.rand(100)*100
z = f(x,y) #the point value calculated by certain function
现在我想获取新的均匀采样坐标(xnew 和 y new)的点值 z
xnew = range(100)
ynew = range(100)
我应该如何使用双线性采样来做到这一点? 我知道可以逐点执行此操作,例如,找到 4 个最近的随机点,然后进行插值,但必须有一些更简单的现有函数来执行此操作
非常感谢!
最佳答案
使用scipy.interpolate.griddata
。它完全满足您的需求
# griddata expects an ndarray for the interpolant coordinates
interpolants = numpy.array([xnew, ynew])
# defaults to linear interpolation
znew = scipy.interpolate.griddata((x, y), z, interpolants)
关于python - python中带有随机点的二维插值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11348708/