How to raise each element of a tensor to a power of another tensor of different size?

Sorry if the title is a bad explanation of what I want, but I had no better way of describing it

I asked a similar question yesterday, at the time of posting this and I got a solution. However it turned out that is not what I want. What I want instead is something like this example:

A= [2, 3]

B= [1, 2, 3]

C= Function(A, B)

and then have it return:

C=[[2, 4, 8], [3, 9, 27]]

But I looked at the documentation as best as I could and still I can’t figure out how to do it without using a fancy for loop. Any ideas are appreciated

Broadcasting should work:

A = torch.tensor([2, 3])
B = torch.tensor([1, 2, 3])

ret = A.unsqueeze(1) ** B
print(ret)
# tensor([[ 2,  4,  8],
#         [ 3,  9, 27]])

In yourr particular example it works pretty well. However it does not work when tensor B is in the form of [B, C, H, W]