2014-01-16 94 views
3

我想插入到scipy中。我在特定時間段t1有3個座標值。scipy中的線性插值

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?

回答

2

看起來像你的x,y,z不必遵循一定的數學模型,所以我想下面應該這樣做。

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

謝謝alot.i瞭解它。 – sam

+0

你能告訴我怎樣才能用新舊座標隨時間繪製圖表? – sam