To simplify my question, let's say I have these arrays:
a = np.array([[1, 2, 3], [4, 5, 6]])
b = np.array([[2, 2, 2], [3, 3, 3]])
c = np.array([[1, 1, 3], [4, 1, 6]])
I would like to use element-wise multiplication on them so the result will be:
array([[ 2, 4, 18],
[ 48, 15, 108]])
I know I can do a*b*c
, but that won't work if I have many 2d arrays or if I don't know the number of arrays. I am also aware of numpy.multiply
but that works for only 2 arrays.
Use
stack
andprod
.stack
will create an array which can be reduced byprod
along an axis.