实现矢量以加快音调计算(numpy.arctan2和np.sqrt)

时间:2019-06-16 02:49:53

标签: python pandas numpy vectorization

尝试使用2个数据点计算数据的音高信息

使用的功能

def pitch_calculate(x,y,z):
  x_Buff = float(x)
  y_Buff = float(y)
  z_Buff = float(z)
  pitch = np.arctan2((- x_Buff) , np.sqrt(y_Buff * y_Buff + z_Buff * z_Buff)) * 57.3
return pitch

熊猫应用

df['PITCH'] = df.apply(lambda x: pitch_calculate(x['x'], x['y'], x['z'] ), axis=1)

如何为此实现矢量计算?

1 个答案:

答案 0 :(得分:1)

df['PITCH'] = np.arctan2(-df.x, np.sqrt(df.y * df.y + df.z * df.z)) * 57.3