4

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)
Divakar
  • 218,885
  • 19
  • 262
  • 358
Demetri Pananos
  • 6,770
  • 9
  • 42
  • 73

1 Answers1

3

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())
Divakar
  • 218,885
  • 19
  • 262
  • 358