问题描述
我在scipy中检查了可用的插值方法,但无法获得适合我的情况的正确解决方案.假设我有100个坐标是随机的点,例如,它们的x和y位置是:
I checked the available interpolation method in scipy, but could not get the proper solution for my case.assume i have 100 points whose coordinates are random,e.g., their x and y positions are:
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
now i want to get the point value z of a new evenly sampled coordinates (xnew and y new)
xnew = range(100)
ynew = range(100)
我应该如何使用双线性采样做到这一点?我知道可以逐点进行操作,例如找到4个最近的随机点,然后进行插值,但是必须有一些更简单的现有函数才能做到这一点
how should i do this using bilinear sampling?i know it is possible to do it point by point, e.g., find the 4 nearest random points, and do the interpolation, but there got to be some easier existing functions to do this
非常感谢!
推荐答案
使用scipy.interpolate.griddata
.它确实满足您的需求
Use scipy.interpolate.griddata
. It does the exact thing you need
# 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中的2D插值随机点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!