Let's say you're given two arrays of vectors:
v1 = np.array([ [1, 2], [3, 4] ]) v2 = np.array([ [10, 20], [30, 40]])
We would like to generate an array that is equivalent to:
v3 = np.array([ np.dot(v1[0], v2[0]), np.dot(v1[1], v2[1]) ])
Currently I use:
v3 = np.einsum('ij,ij->i', v1, v2)
However, I do this a lot in my code, so speed ups here would be very helpful for me.
How could we speed it up? np.einsum is already quite efficient, but I wonder if for this particular use-case, there is a faster way?