快捷方式

torch.pow

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

计算 input 中每个元素与 exponent 的幂,并返回包含结果的张量。

exponent 可以是单个 float 数字,也可以是与 input 元素数量相同的 Tensor

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

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

exponent 是张量时,应用的操作是

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

exponent 是张量时,inputexponent 的形状必须是 可广播的

参数
  • input (Tensor) – 输入张量。

  • exponent (floattensor) – 指数值

关键字参数

out (Tensor, optional) – 输出张量。

示例

>>> a = torch.randn(4)
>>> a
tensor([ 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.)
>>> a
tensor([ 1.,  2.,  3.,  4.])
>>> exp
tensor([ 1.,  2.,  3.,  4.])
>>> torch.pow(a, exp)
tensor([   1.,    4.,   27.,  256.])
torch.pow(self, exponent, *, out=None) Tensor

self 是标量 float 值,exponent 是张量。返回的张量 out 的形状与 exponent 相同

应用的操作是

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

  • exponent (Tensor) – 指数张量

关键字参数

out (Tensor, optional) – 输出张量。

示例

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

文档

访问 PyTorch 的综合开发者文档

查看文档

教程

获取面向初学者和高级开发者的深度教程

查看教程

资源

查找开发资源并获得您的问题解答

查看资源