scipy中的线性插值

时间:2014-01-16 04:26:03

标签: python numpy scipy

我想在scipy中进行插值。我在特定时间段t1有3个坐标值。

x    44.254 44.114  44.353  44.899  45.082
y    -0.934 0.506   1.389   0.938   0.881
z    44.864 45.225  44.005  42.981  46.356

在时间t1

t1    0  0.0005413307  0.0010949014 0.0015468832    0.0027740823

我需要在时间t2找到坐标。

t2    0  0.00392157  0.00784314  0.01176471  0.01568627  0.019607

我有x,t1和t2为numpy数组。

x     [ [44.254 44.114  44.353  44.899  45.082] [-0.934 0.506   1.389   0.938   0.881] [44.864  45.225  44.005  42.981  46.356]]
t1    [ 0  0.0005413307  0.0010949014  0.0015468832 0.0027740823]
t2    [ 0  0.00392157  0.00784314  0.01176471  0.01568627  0.019607]

我如何使用scipy.interp1?

1 个答案:

答案 0 :(得分:2)

您的xyz看起来不一定要遵循某些数学模型,所以我想以下内容应该这样做。

>>> x=np.array([44.254, 44.114,  44.353,  44.899,  45.082])
>>> y=np.array([-0.934, 0.506,   1.389,   0.938,   0.881])
>>> z=np.array([44.864, 45.225,  44.005,  42.981,  46.356])
>>> t1=np.array([0,  0.0005413307,  0.0010949014, 0.0015468832,    0.0027740823])
>>> t2=np.array([0,  0.00392157,  0.00784314,  0.01176471,  0.01568627,  0.019607])
>>> scipy.interp(t2, t1,x)
array([ 44.254,  45.082,  45.082,  45.082,  45.082,  45.082])
>>> scipy.interp(t2, t1,y)
array([-0.934,  0.881,  0.881,  0.881,  0.881,  0.881])
>>> scipy.interp(t2, t1,z)
array([ 44.864,  46.356,  46.356,  46.356,  46.356,  46.356])
>>> indata=np.vstack((x,y,z))
>>> np.apply_along_axis(lambda A: scipy.interp(t2,t1,A), 1, indata)
array([[ 44.254,  45.082,  45.082,  45.082,  45.082,  45.082],
       [ -0.934,   0.881,   0.881,   0.881,   0.881,   0.881],
       [ 44.864,  46.356,  46.356,  46.356,  46.356,  46.356]])