Let's say I have a N × 1 × 1 array a
, and N × M × M array b
as NumPy arrays. I want to do the elementwise multiplication:
c[i,:,:] = a[i]*b[i,:,:]
without iterating over i
. The function np.multiply(a,b)
seems to do the job. However, I do not quite understand the inner workings of this function when a
and b
do not have the same size. I know that when it has the same size then it just multiplies elementwise. I assume when they are not of the same size then it does some broadcasting to change the dimensions of one of the arrays but how?