Thanks for help. I have solved the problem. What I need is something like this. If my matrix M is of size [2, 10572] and n is of size [3]. I can do M[:, None, :] ** n[:, None] and get output of size [2, 3, 10572]. Then i just need to sum along axis 1.
I think this is very efficient. Not sure about other solutions provided here though. Have not tested.