Skip to main content
 首页 » 编程设计

python之scipy.interpolate.LinearNDInterpolator 没有产生所需的功能

2025年05月04日15JustinYoung

我没有使用 LinearNDInterpolator 获得所需的 2D 线性插值功能。下面的一段代码试图在 4 个结点 (0,0)、(1,0)、(0,1)、(1,1) 之间进行插值。 interp2d 给了我预期的(线性插值)结果,但 LinearNDInterpolator 正在做其他事情,我无法弄清楚。也许我没有正确使用 API。不幸的是,我找不到有关用法的详细文档。有人可以帮助或指出我要写信给正确的论坛(mathoverflow 吗?)?

>>> f = interp2d([0,1,0,1], [0,0,1,1], [0,1,2,4]) 
>>> f(0.5,0.5) 
array([ 1.75]) 
>>> g = LinearNDInterpolator([[0,0],[1,0],[0,1],[1,1]], [0,1,2,4]) 
>>> g(0.5,0.5) 
array(2.0) 

请您参考如下方法:

来自 http://docs.scipy.org/doc/scipy/reference/generated/scipy.interpolate.LinearNDInterpolator.html :

The interpolant is constructed by triangulating the input data with Qhull [R15], and on each triangle performing linear barycentric interpolation.

在您的例子中,所选三角形似乎共享 (0,0), (1,1) 边。由于 (0.5, 0.5) 位于 (0,0) 和 (1,1) 之间,因此插值位于以下值之间那些顶点,所以它是 (0+4)/2 = 2.0。