Given a 3d array and a 2d array,
a = np.arange(10*4*3).reshape((10,4,3))
b = np.arange(30).reshape((10,3))
How can I run elementwise-multiplication across the final axis of each, resulting in c where c has the shape .shape as a? I.e.
c[0] = a[0] * b[0]
c[1] = a[1] * b[1]
# ...
c[i] = a[i] * b[i]
Without any sum-reduction involved, a simple
broadcastingwould be really efficient after extendingbto3Dwithnp.newaxis/None-Runtime test -