Suppose I have two 2-dimensional tensors with the same batch dimension (that is, same number of rows).
import numpy as np
# Both t1 and t2 have shape (2, 3)
t1 = np.array([[1.0, 2.0, 3.0], [10.0, 11.0, 12.0]])
# array([[ 1., 2., 3.],
# [10., 11., 12.]])
t2 = np.array([[21.0, 22.0, 23.0], [30.0, 31.0, 32.0]])
# array([[21., 22., 23.],
# [30., 31., 32.]])
How do I compute the dot product between the rows of the two tensors? Specifically, I want to end up with the desired (2, 1) tensor result:
desired_result = np.array([np.dot(t1[0], t2[0]), np.dot(t1[1], t2[1])])
# array([ 134., 1025.])
I already tried:
np.dot(t1, t2)
# Traceback (most recent call last):
# File "<stdin>", line 1, in <module>
# File "<__array_function__ internals>", line 5, in dot
# ValueError: shapes (2,3) and (2,3) not aligned: 3 (dim 1) != 2 (dim 0)
np.tensordot(t1, t2)
# array(1159.)
Thanks for any help.