使用NumPy/SciPy进行矢量值函数插值 [英] Vector-valued function interpolation using NumPy/SciPy

查看:116
本文介绍了使用NumPy/SciPy进行矢量值函数插值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以使用 NumPy /科学?

有很多处理标量值函数的产品,我想我可以使用其中的一种来分别估计向量的每个分量,但是有一种方法可以更有效地做到这一点?

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆