2014-01-16 71 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