私はy = [0,100,200,300,400]、x = [0,28,54,78,100]のようなデータセットの3次補間をしようとしています。 numpyライブラリの線形補間では、すべて正常に機能しますが、スムーズなデータセットが必要です。その結果、以下のコードサンプルがどのように見えるのデータセットである場合:enter image description hereどのようにして3次補間でより大きな配列を作成し、すべての計算値にアクセスできますか?
代わりに、私はこのようになり、データ・セットたい: enter image description here を補間が私に私にアクセスすることができます配列を与えることを私のために重要です2秒ごとにDistanceLong値に加算します。これが係数です。 scipy機能では、私はそれを動作させることができませんでした。私はあなたが私にいくつかの助けを与えることができます願っています!キュービック補間のために
import numpy as np
import matplotlib.pyplot as plt
def interplan(Timestamp, Distance, factor):
Time = np.zeros(len(Timestamp)-1)
NewDistance= np.zeros(len(Timestamp)-1)
TotalTime = 0
TotalDistance = 0
for i in range(len(Timestamp)-1):
TotalTime += Timestamp[i]
Time[i] = TotalTime
TotalDistance += Distance[i]
NewDistance[i] = TotalDistance
Time = np.hstack((0,Time))
NewDistance = np.hstack((0,NewDistance))
k = np.array(range((int(TotalTime+1))))
t = k*factor
DistanceLong = np.interp(t,Time,NewDistance)
return DistanceLong
Timestamp = np.array([28, 26, 24, 22,0])
Distance = np.array([100, 100, 100, 100,0])
factor = 2
DistanceLong = interplan(Timestamp, Distance, factor)
BiggestVal = max(DistanceLong)
IndexLastVal = np.where(DistanceLong == BiggestVal)
DistanceLong = DistanceLong[0:IndexLastVal[0][1]]
Speed = np.zeros(len(DistanceLong))
for i in range(len(DistanceLong)-1):
Speed[i] = ((DistanceLong[i+1]-DistanceLong[i])/2)*3.6
PerfectSpeed = (Distance/Timestamp)*3.6
plt.figure(1)
plt.plot(Speed,linewidth=0.8)
plt.figure(2)
plt.plot(PerfectSpeed,linewidth=0.8)
CubicSplineを使用しているときに値にアクセスできません。私がそれを印刷すると、次のようになります。 –
CubicSplineは、その引数に補間を評価する呼び出し可能なオブジェクトを作成します。 –