2
我們將測量結果(飛行數據)存儲在熊貓數據框中。如何在熊貓時間序列中存儲矢量?
我們希望能夠有一個場「速度」,這是速度的x,y和z分量的向量。如計算速度的範數或計算兩個速度的標量乘積並將結果存儲在數據幀的新時間序列中,將比較容易進行計算 。
有沒有辦法用熊貓做到這一點?
實施例:
import numpy as np
import numpy.linalg as la
fdo = Store()
df = fdo.getDataFrame(5)
# this works; there are three time series now, that contain the velocity
print df.vx, df.vy, df. vz
# create a vector of velocity vectors
velocities = np.column_stack((df.vx, df.vy, df.vz))
# this does not work:
df['velocities'] = velocities
print "Start calculation!"
# calculate a vector of the norms of this vector (simple method)
norm1 = np.apply_along_axis(la.norm, 1, velocities)
print np.nansum(norm1)
# calculate a vector of the norms of this vector (fast method)
norm2 = np.sum(np.abs(velocities)**2, axis=-1)**(1./2)
print np.nansum(norm2)