Is There a Power Function for Tensors in Pytorch?

Is there an equivalent of numpy.power in pytorch?

The function basically raises each element in the first tensor to the power represented in each corresponding element in the second tensor.

1 Answer

You are looking for torch.pow.

As mentioned by @Szymon Maszke, you can also use ** operator:

y = torch.pow(x, y)
# the same as
y = x ** y
# and also the same as
y = x.pow(y)

where y can be a scalar or a tensor with shape broadcastable to x's shape.

2

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Sarah Jenkins

Sarah Jenkins

Senior Technology Editor & AI Specialist

Sarah Jenkins is a veteran tech journalist with over 12 years of experience covering artificial intelligence, mobile innovations, and digital ethics. Her insights have appeared in leading technology publications worldwide.

Share this article
Twitter Facebook Pinterest