本文介绍了scipy.interpolate.LinearNDInterpolator 没有产生所需的功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我没有使用 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)数组([1.75])>>>g = LinearNDInterpolator([[0,0],[1,0],[0,1],[1,1]], [0,1,2,4])>>>克(0.5,0.5)数组(2.0)
解决方案

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

插值是通过使用 Qhull [R15] 对输入数据进行三角剖分构建的,并在每个三角形上执行线性重心插值.

在您的情况下,选择的三角形似乎共享 (0,0), (1,1) 边.由于 (0.5, 0.5) 介于 (0,0)(1,1) 之间,所以内插值位于那些顶点,所以它是 (0+4)/2 = 2.0.

I am not getting the desired 2D linear interpolation functionality with LinearNDInterpolator. The following piece of code is trying to do an interpolation between the 4 knot points (0,0), (1,0), (0,1), (1,1). interp2d gives me the expected (linear-interpolated) result but LinearNDInterpolator is doing something else, which I am unable to figure out. Perhaps I am not using the API correctly. Unfortunately, I can't find detailed docs on the usage. Can someone please help or point me to the right forum (mathoverflow ?) to write to ?

>>> 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)
解决方案

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

In your case, the triangles chosen appear to share the (0,0), (1,1) edge. Since (0.5, 0.5) is midway between (0,0) and (1,1), the interpolated value lies between the values at those vertices, so it is (0+4)/2 = 2.0.

这篇关于scipy.interpolate.LinearNDInterpolator 没有产生所需的功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-05 15:00