Numpy ndarray multiplication

前端 未结 2 1311
[愿得一人]
[愿得一人] 2021-01-21 05:33

I have two 3D numpy ndarray

A=np.array([[[1, 1],
             [1, 1],
             [1, 1]],

            [[2, 2],
             [2, 2],
             [2, 2]]])

B=         


        
2条回答
  •  别那么骄傲
    2021-01-21 06:14

    ABijk=∑m (Aijm*Bimk) translates to

    AB = np.einsum('ijm,imk->ijk', A, B)
    

    I think the matmul operator will also handle this

    AB = A @ B
    

    since it takes the normal dot on the the last 2 dimensions, carrying the rest along as free baggage.

    Test those and let me know if they work.

提交回复
热议问题