Shortcuts

torch.pow

torch.pow(input, exponent, *, out=None) 张量

input 中的每个元素的幂次方与 exponent 相乘,并返回一个包含结果的张量。

exponent 可以是单个 float 数字或一个 Tensor,其元素数量与 input 相同。

exponent 是一个标量值时,应用的操作是:

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

exponent 是一个张量时,应用的操作是:

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

exponent 是一个张量时,inputexponent 的形状必须是可以广播的。

Parameters
  • 输入 (张量) – 输入张量。

  • 指数 (浮点数张量) – 指数值

Keyword Arguments

输出 (张量, 可选) – 输出张量。

示例:

>>> a = torch.randn(4)
>>> a
张量([ 0.4331,  1.2475,  0.6834, -0.2791])
>>> torch.pow(a, 2)
张量([ 0.1875,  1.5561,  0.4670,  0.0779])
>>> exp = torch.arange(1., 5.)

>>> a = torch.arange(1., 5.)
>>> a
张量([ 1.,  2.,  3.,  4.])
>>> exp
张量([ 1.,  2.,  3.,  4.])
>>> torch.pow(a, exp)
张量([   1.,    4.,   27.,  256.])
torch.pow(self, exponent, *, out=None) 张量

self 是一个标量 float 值,而 exponent 是一个张量。 返回的张量 outexponent 具有相同的形状

应用的操作是:

outi=selfexponenti\text{out}_i = \text{self} ^ {\text{exponent}_i}
Parameters
  • self (float) – 幂运算的标量基值

  • 指数 (张量) – 指数张量

Keyword Arguments

输出 (张量, 可选) – 输出张量。

示例:

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