我编写了下面的函数,用于从3轴加速度计信号(X、Y、Z)估计方向。
X.shape
Out[4]: (180000L,)
Y.shape
Out[4]: (180000L,)
Z.shape
Out[4]: (180000L,)
def estimate_orientation(self,X,Y,Z):
sigIn=np.array([X,Y,Z]).T
N=len(sigIn)
sigOut=np.empty(shape=(N,3))
sigOut[sigOut==0]=None
i=0
while i<N:
sigOut[i,:] = np.arccos(sigIn[i,:]/np.linalg.norm(sigIn[i,:]))*180/math.pi
i=i+1
return sigOut
使用 180000 个样本的信号执行此函数需要相当长的时间(约为2.2秒)... 我知道它不是以“Pythonic方式”编写的... 你能帮我优化执行时间吗?
谢谢!