Numpy 2-D & 3-D matrix “row”-wise multiplication

前端 未结 1 1626
感动是毒
感动是毒 2020-12-07 05:58

I started learning numpy and I\'m trying to do a kind of strange matrix multiplication between a 2-dimensional and a 3-dimensional matrices. I have a function that does what

相关标签:
1条回答
  • 2020-12-07 06:41

    You can use np.einsum -

    np.einsum('ij,ijk->ik',array1,array2)
    

    Or with np.matmul or @ operator on Python 3.x -

    np.matmul(array1[:,None,:],array2)[:,0]
    (array1[:,None,:] @ array2)[:,0]
    
    0 讨论(0)
提交回复
热议问题