I have two matrices consisting of 3d vectors (numpy 1D arrays) and I need to calculate the angle between the vectors, row-wise, and return the results in a 1d array. I know how to calculate the angle between two 1d vectors. What is the the proper way to do this?
*** The resulting angles are in degrees not radians.
By now I have this:
import numpy as np
A = np.array([[1,0,0],
[0,1,0],
[0,0,1]])
B = np.array([[1,0,1],
[1,1,0],
[0,1,0]])
def angle(V1,V2):
"""
angle between vectors V1 and V2 in degrees using
angle = arccos ( V1 dot V2 / norm(V1) * norm(V2) ) *180/np.pi
"""
cos_of_angle = V1.dot(V2) / (np.linalg.norm(V1) * np.linalg.norm(V2))
return np.arccos(np.clip(cos_of_angle,-1,1)) * 180/np.pi
Note the scaling term 180/np.pi for the conversion from rad to deg.
I would like to have an array:
C = [ angle(A[0],B[0]) , angle(A[1],B[1])...... and so on]
Really appreciated if someone could help.