[英]2d interpolation in python with random spot
I checked the available interpolation method in scipy, but could not get the proper solution for my case. 我在scipy中检查了可用的插值方法,但无法为我的情况得到正确的解决方案。 assume i have 100 points whose coordinates are random, eg, their x and y positions are:
假设我有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
now i want to get the point value z of a new evenly sampled coordinates (xnew and y new) 现在我想得到一个新的均匀采样坐标的点值z(xnew和y new)
xnew = range(100)
ynew = range(100)
how should i do this using bilinear sampling? 我应该如何使用双线性采样? i know it is possible to do it point by point, eg, find the 4 nearest random points, and do the interpolation, but there got to be some easier existing functions to do this
我知道可以逐点进行,例如,找到最近的4个随机点,并进行插值,但是必须有一些更容易的现有函数才能做到这一点
thanks alot! 非常感谢!
Use scipy.interpolate.griddata
. 使用
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)
http://docs.scipy.org/doc/scipy/reference/generated/scipy.interpolate.griddata.html#scipy.interpolate.griddata http://docs.scipy.org/doc/scipy/reference/generated/scipy.interpolate.griddata.html#scipy.interpolate.griddata
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.