python - python中带有随机点的二维插值

标签 python numpy scipy

我检查了 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) 

http://docs.scipy.org/doc/scipy/reference/generated/scipy.interpolate.griddata.html#scipy.interpolate.griddata

关于python - python中带有随机点的二维插值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11348708/

相关文章:

python - 将 ManyToManyField 拆分为 ModelForm 中的多个表单字段

python - 需要在重新启动之前停止 aws ec2 实例中的服务

python - 列出使用 gspread 创建的谷歌电子表格

python - 在python中的不规则网格上集成二维数据

python - Hotelling 在 python 中的 T^2 分数

python - scipy.fft 链接到 numpy.fft.fftpack.fft 的事实是否记录在任何地方?

python - 加快 numpy 过滤速度

python - 用正则表达式模式替换

python - 具有多种数据类型的 Python 中的 3D 数组

python - 比 numpy.where 更快的替代品?