Rate this Page

torch.pow#

torch.pow(input,exponent,*,out=None)Tensor#

Takes the power of each element ininput withexponent andreturns a tensor with the result.

exponent can be either a singlefloat number or aTensorwith the same number of elements asinput.

Whenexponent is a scalar value, the operation applied is:

outi=xiexponent\text{out}_i = x_i ^ \text{exponent}

Whenexponent is a tensor, the operation applied is:

outi=xiexponenti\text{out}_i = x_i ^ {\text{exponent}_i}

Whenexponent is a tensor, the shapes ofinputandexponent must bebroadcastable.

Parameters
  • input (Tensor) – the input tensor.

  • exponent (float ortensor) – the exponent value

Keyword Arguments

out (Tensor,optional) – the output tensor.

Example:

>>>a=torch.randn(4)>>>atensor([ 0.4331,  1.2475,  0.6834, -0.2791])>>>torch.pow(a,2)tensor([ 0.1875,  1.5561,  0.4670,  0.0779])>>>exp=torch.arange(1.,5.)>>>a=torch.arange(1.,5.)>>>atensor([ 1.,  2.,  3.,  4.])>>>exptensor([ 1.,  2.,  3.,  4.])>>>torch.pow(a,exp)tensor([   1.,    4.,   27.,  256.])
torch.pow(self,exponent,*,out=None)Tensor

self is a scalarfloat value, andexponent is a tensor.The returned tensorout is of the same shape asexponent

The operation applied is:

outi=selfexponenti\text{out}_i = \text{self} ^ {\text{exponent}_i}
Parameters
  • self (float) – the scalar base value for the power operation

  • exponent (Tensor) – the exponent tensor

Keyword Arguments

out (Tensor,optional) – the output tensor.

Example:

>>>exp=torch.arange(1.,5.)>>>base=2>>>torch.pow(base,exp)tensor([  2.,   4.,   8.,  16.])