I'm doing a whole bunch of hadamard products, as part of a machine learning project. To convey the problem, below is the setup:
# shape: (2, 3)
In [17]: arr1
Out[17]:
array([[0.44486617, 0.21001534, 0.63833794],
[0.90878526, 0.61692562, 0.01978946]])
# shape: (5, 3)
In [18]: arr2
Out[18]:
array([[0.00640485, 0.22768134, 0.62845291],
[0.58168743, 0.65527711, 0.14765079],
[0.61389269, 0.38546809, 0.62696518],
[0.73977707, 0.03737199, 0.45905132],
[0.51932163, 0.00119124, 0.07241033]])
Now, I want to perform a hadamard product of each of the rows in arr1
with arr2
and thus obtain the resultant array, call it res
, of shape (10, 3)
.
(2, 3)
* |
(5, 3)
||
(10,3)
How can we do this with the least possible overhead using only NumPy?