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

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

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.

You Might Also Like