Let's say you have two lists of vectors:
v1s = [a, b, c]
v2s = [d, e, f]
I am interested in generating the following result:
angles = [angleBetween(a, d), angleBetween(b, e), angleBetween(c, f)]
Here is my function to do this (it uses vector dot products in order to calculate the angles):
import numpy as np def findAnglesBetweenTwoVectors(v1s, v2s): dot_v1_v2 = np.einsum('ij,ij->i', v1s, v2s) dot_v1_v1 = np.einsum('ij,ij->i', v1s, v1s) dot_v2_v2 = np.einsum('ij,ij->i', v2s, v2s) return np.arccos(dot_v1_v2/(np.sqrt(dot_v1_v1)*np.sqrt(dot_v2_v2)))
I call this function a lot, so optimizing it would be very helpful for me. Is this possible?