How to get element-wise matrix multiplication (Hadamard product) in numpy?

后端 未结 4 1412
無奈伤痛
無奈伤痛 2020-11-27 15:05

I have two matrices

a = np.matrix([[1,2], [3,4]])
b = np.matrix([[5,6], [7,8]])

and I want to get the element-wise product, [[1*5,2*

4条回答
  •  粉色の甜心
    2020-11-27 15:30

    just do this:

    import numpy as np
    
    a = np.array([[1,2],[3,4]])
    b = np.array([[5,6],[7,8]])
    
    a * b
    

提交回复
热议问题