You have an array of shape (a,b,c) and you want to multiply the second dimension by an array of shape (b)
A for loop would work, but is there a better way?
Ex.
A = np.array(shape=(a,b,c))
B = np.array(shape=(b))
for i in B.shape[0]:
A[:,i,:]=A[:,i,:]*B[i]
Use broadcasting:
For example:
B[:,np.newaxis]has shape (3,1). Broadcasting adds new axes on the left,so this is broadcasted to shape (1,3,1). Broadcasting also repeats the items along axes with length 1. So when multiplied with
A, it gets further broadcasted to shape (2,3,4). This matches the shape ofA. Multiplication then proceeds element-wise, as always.