How to get element-wise matrix multiplication (Hadamard product) in numpy?
<p>I have two matrices </p>

<pre><code>a = [[1,2][3,4]]
b = [[5,6][7,8]]
</code></pre>

<p>I want to get the element-wise prodcut which will be <code>[[1*5,2*6][3*7,4*8]]</code> equals to </p>

<p><code>[[5,12][21,32]]</code></p>

<p>I tried with numpy </p>

<pre><code>print(np.dot(x,y)) 
</code></pre>

<p>and</p>

<pre><code>print(x*y)
</code></pre>

<p>result: <code>[[19 22][43 50]]</code></p>

<p>which gives me the matrix multiplication result not element-wise product. How can I get the the element-wise product aka. Hadamard product using built-in functions ?</p>

<p>Try this,</p>

<pre><code>import numpy as np
a = np.array([[1,2],[3,4]])
b = np.array([[5,6],[7,8]])
np.multiply(a,b)
</code></pre>

<p><strong>Result</strong> </p>

<pre><code>array([[ 5, 12],
       [21, 32]])
</code></pre>

python numpy matrix matrix-multiplication elementwise-operations