Python中的2D插值随机点 [英] 2d interpolation in python with random spot

查看:240
本文介绍了Python中的2D插值随机点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在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) 

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

这篇关于Python中的2D插值随机点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆