numpy element-wise multiplication of an array and a vector
问题 I want to do something like this: a = # multi-dimensional numpy array ares = # multi-dim array, same shape as a a.shape >>> (45, 72, 37, 24) # the relevant point is that all dimension are different v = # 1D numpy array, i.e. a vector v.shape >>> (37) # note that v has the same length as the 3rd dimension of a for i in range(37): ares[:,:,i,:] = a[:,:,i,:]*v[i] I'm thinking there has to be a more compact way to do this with numpy, but I haven't figured it out. I guess I could replicate v and