Scipy中的线性插值

3

我希望在scipy中进行插值。我有3个坐标值,对应于特定时间段t1。

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

我有三个numpy数组:x、t1和t2。

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个回答

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]])

你能告诉我如何在图表中绘制旧坐标和新坐标随时间变化的数据吗? - sam

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接