Reputation: 19204
I want to interpolate in scipy. I have 3 coordinate values at specific time period 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
at time t1
t1 0 0.0005413307 0.0010949014 0.0015468832 0.0027740823
I need to find coordinates at time t2.
t2 0 0.00392157 0.00784314 0.01176471 0.01568627 0.019607
I have x, t1 and t2 as numpy array.
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]
How can I use scipy.interp1?
Upvotes: 3
Views: 318
Reputation: 54380
Looks like your x
, y
, z
do not have to follow certain mathematical model, so I guess the following should do it.
>>> 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]])
Upvotes: 2