numpy: multiply arrays rowwise
For those who don't want to use np.newaxis
or reshape
, this is as simple as:
a * b[:, None]
This is because np.newaxis
is actually an alias for None
.
Read more here.
add an axis to b:
>>> np.multiply(a, b[:, np.newaxis])
array([[ 1, 2],
[ 6, 8],
[15, 18],
[28, 32]])