Multiply two matrix by columns with python

后端 未结 2 2091
猫巷女王i
猫巷女王i 2020-12-18 09:06

I have two matrix:

A = [a11 a12 

     a21 a22]


B = [b11 b12
     b21 b22]

And I want to multiply all its columns (without loops) in orde

2条回答
  •  离开以前
    2020-12-18 09:15

    b = np.tile(B, 2) # two copies of B, side by side
    a = np.tile(A, 2)
    a = np.hstack((a[:,::2], a[:,1::2])) # change 1,2,1,2 to 1,1,2,2
    a * b # done
    

    I expect there is a better way to do the third step, but the above works and is relatively efficient.

提交回复
热议问题