War*_*ick 5 python interpolation
在Python中,我正在尝试构建一个在多维(5+)参数空间中插入向量值数据的例程.即我有一个函数,它接受许多输入变量并返回许多输出变量.目前,对向量的每个元素都有一个调用.数据在一个圆柱文件中,所以我用它检索它
import numpy
[x_data,y_data,f1_data,f2_data] = numpy.loadtxt('data',unpack=True)
Run Code Online (Sandbox Code Playgroud)
然后,我使用SciPy函数实例化各个插值器,如
from scipy import interpolate
f1 = interpolate.LinearNDInterpolator((x_data,y_data),f1_data)
f2 = interpolate.LinearNDInterpolator((x_data,y_data),f2_data)
...
Run Code Online (Sandbox Code Playgroud)
现在,当我做插值电话,我要插每个值f1,f2等等.尽管实际上它应该是可以实现的一个操作.而且我猜测制作一个插值应该比制作5个或更多更快.
有没有办法构建矢量(或数组)值插值器?
我尝试使用构造插值器
f = interpolate.LinearNDInterpolator((x_data,y_data),(f1_data,f2_data,...))
Run Code Online (Sandbox Code Playgroud)
但它返回错误
ValueError:不同数量的值和点
我也读过这个问题和答案,但它是关于标量的向量值函数,显然可以用它来处理interp1d.
scipy.interpolate.LinearNDInterpolator期望以行主顺序接收其数据:例如,在您的情况下,第一个参数需要是一对数组,而不是一对数组.由于您在加载数据时转换了数据,因此在将数据传递给数据之前,您必须将其重新转置LinearNDInterpolator.尝试类似的东西:
points = numpy.array((x, y)).T
values = numpy.array((f1, f2)).T
f = interpolate.LinearNDInterpolator(points, values)
Run Code Online (Sandbox Code Playgroud)