I have a multidimensional array whose shape is (32,3,5,5) and an array with shape (32). How can I multiply (i, 3,5,5) by (i,) for each i using numpy other than for loop?
With a and b as two arrays, several approaches can be suggested -
a
b
a*b[:,None,None,None] a*b.reshape(-1,*[1]*3) (a.T*b).T np.einsum('i...,i->i...',a,b)