使用NumPy/SciPy进行矢量值函数插值 [英] Vector-valued function interpolation using NumPy/SciPy
问题描述
有很多处理标量值函数的产品,我想我可以使用其中的一种来分别估计向量的每个分量,但是有一种方法可以更有效地做到这一点?
There are plenty of offerings that work on scalar-valued functions, and I guess I can use one of those to estimate each component of the vector separately, but is there a way to do it more efficiently?
为了详细说明,我有一个函数f(x) = V
,其中x
是标量,而V
是向量.我也有一个xs
及其对应的Vs
的集合.我想用它来为任意x
内插和估算V
.
To elaborate, I have a function f(x) = V
, where x
is scalar and V
is a vector. I also have a collection of xs
and their corresponding Vs
. I would like to use it to interpolate and estimate V
for an arbitrary x
.
推荐答案
插值函数scipy.interpolate.interp1d
还可用于插值的矢量值数据(尽管不适用于矢量值参数数据).因此,只要x
是标量,就可以直接使用它.
The interpolation function scipy.interpolate.interp1d
also works on vector-valued data for the interpolant (not for vector-valued argument data though). Thus, as long as x
is scalar, you can use it directly.
以下代码是 scipy文档:
>>> from scipy.interpolate import interp1d
>>> x = np.linspace(0, 10, 10)
>>> y = np.array([np.exp(-x/3.0), 2*x])
>>> f = interp1d(x, y)
>>> f(2)
array([ 0.51950421, 4. ])
>>> np.array([np.exp(-2/3.0), 2*2])
array([ 0.51341712, 4. ])
请注意,参数向量x
中没有2,因此在此示例中,y
中第一个分量的插值误差.
Note that 2 is not in the argument vector x
, thus the interpolation error for the first component in y
in this example.
这篇关于使用NumPy/SciPy进行矢量值函数插值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!