RegularGridInterpolator

RegularGridInterpolator

我对 documentation for scipy.interpolate.RegularGridInterpolator 有点困惑。

比如说我有一个函数 f: R^3 => R,它是在单位立方体的顶点上采样的。我想进行插值以便在多维数据集中找到值。

import numpy as np

# Grid points / sample locations
X = np.array([[0,0,0], [0,0,1], [0,1,0], [0,1,1], [1,0,0], [1,0,1], [1,1,0], [1,1,1.]])

# Function values at the grid points
F = np.random.rand(8)

现在,RegularGridInterpolator 接受一个 points 参数和一个 values 参数。



我将此解释为能够这样调用:
import scipy.interpolate as irp

rgi = irp.RegularGridInterpolator(X, F)

但是,当我这样做时,我收到以下错误:



我在文档中误解了什么?

最佳答案

您的回答更好,您完全可以接受。我只是将其添加为编写脚本的“替代”方式。

import numpy as np
import scipy.interpolate as spint

RGI = spint.RegularGridInterpolator

x = np.linspace(0, 1, 3) #  or  0.5*np.arange(3.) works too

# populate the 3D array of values (re-using x because lazy)
X, Y, Z = np.meshgrid(x, x, x, indexing='ij')
vals = np.sin(X) + np.cos(Y) + np.tan(Z)

# make the interpolator, (list of 1D axes, values at all points)
rgi = RGI(points=[x, x, x], values=vals)  # can also be [x]*3 or (x,)*3

tst = (0.47, 0.49, 0.53)

print rgi(tst)
print np.sin(tst[0]) + np.cos(tst[1]) + np.tan(tst[2])

返回:
1.93765972087
1.92113615659

关于python - scipy.interpolate.RegularGridInterpolator 的正确使用,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/30056577/

10-13 07:29