我有点被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
参数。
points : tuple of ndarray of float, with shapes (m1, ), ..., (mn, ) The points defining the regular grid in n dimensions.
values : array_like, shape (m1, ..., mn, ...) The data on the regular grid in n dimensions.
我将此解释为能够这样调用:
import scipy.interpolate as irp
rgi = irp.RegularGridInterpolator(X, F)
但是,当我这样做时,会出现以下错误:
ValueError: There are 8 point arrays, but values has 1 dimensions
我在文件里误解了什么?
你的回答更好,你完全可以接受。我只是添加这个作为一个“替代”的方式来编写它。
返回:
好吧,当我回答自己的问题时,我觉得很傻,但是我在原始库的文档中发现了我的错误:
https://github.com/JohannesBuchner/regulargrid
points
应该是一个数组列表,指定点沿每个轴的间距。例如,要采用上述单位立方体,我应该设置:
或者,如果我有沿最后一个轴以更高分辨率采样的数据,我可以设置:
最后,
values
的形状必须与由points
隐式布置的网格相对应。例如所以最后
按需运行和执行。
相关问题 更多 >
编程相关推荐