How can I write the following dot product using einstein notation?
import numpy as np
LHS = np.ones((5,20,2))
RHS = np.ones((20,2))
np.sum([
np.dot(LHS[:,:,0], RHS[:,0]),
np.dot(LHS[:,:,1], RHS[:,1]),
], axis=0)
How can I write the following dot product using einstein notation?
import numpy as np
LHS = np.ones((5,20,2))
RHS = np.ones((20,2))
np.sum([
np.dot(LHS[:,:,0], RHS[:,0]),
np.dot(LHS[:,:,1], RHS[:,1]),
], axis=0)
That would be -
np.einsum('ijk,jk->i',LHS,RHS)
Alternatively with tensordot
-
np.tensordot(LHS,RHS,axes=((1,2),(0,1)))
And with np.dot
-
LHS.reshape(LHS.shape[0],-1).dot(RHS.ravel())