How to calculate the outer product of two matrices A and B per rows faster in python (numpy)?

后端 未结 1 449
长发绾君心
长发绾君心 2020-12-11 22:47

Let say we have two matrices A and B.

A has the shape (r, k) and B has the shape (r, l).

Now I want to calculate the np.outer product of these two matrices p

相关标签:
1条回答
  • 2020-12-11 23:23

    You could literally transfer the iterators as string notation to np.einsum -

    np.einsum('rk,rl->kl',A,B)
    

    Or with matrix-multiplication using np.dot -

    A.T.dot(B)
    
    0 讨论(0)
提交回复
热议问题