How do I raise a constant to the power of a tensor?

I want to take raise 2 to the power of a tensor A and then have it return another tensor B but with B with all elements of B be 2 but raised to the coresponding exponent. For example:

A= [1, 2, 3]

B= Function(2, A)

B= [2, 4, 8]

However I still haven’t figured out how to make such a function. Any ideas?

Could you try 2**A?

Wouldn’t that cause issues with back-propagation tho?

I don’t see why not, give it a go and see if it works. Or you can quickly do something like,

A = torch.randn(3, requires_grad=True)
B = 2**A
print(B.grad_fn) #if there's a grad function, back-prop is fine

It prints <PowBackward1 object at 0x00000173EF314808> so I suppose it works