Exponentiation of a tensor by another tensor

I’m trying to exponentiate a tensor A of size [m] to another tensor B of size [n] element-wise, meaning each element in A should be exponentiated to every element in B resulting in another tensor C of size [m, n].

e.g. if A = [2, 3, 4] and B = [2, 3] then C=[ [2^2, 2^3], [3^2, 3^3], [4^2, 4^3] ]

the only efficient way I found is doing this:
C = A.unsqueeze(1) ** B.unsqueeze(0)

Is there a better way to do it?

That’s pretty efficient as-is.

1 Like

thank you so much :slight_smile: