• 文档 >
  • torch >
  • torch.pow
快捷键

torch.pow

torch.pow(input, 指数, *, 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) – 输入张量。

  • 指数(浮点数或张量)- 指数值

关键字参数:

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

示例:

>>> 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, 指数, *, out=None) → Tensor

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

使用的操作是:

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

  • 指数 (Tensor) – 幂运算的张量

关键字参数:

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

示例:

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

© 版权所有 PyTorch 贡献者。

使用 Sphinx 构建,并使用 Read the Docs 提供的主题。

文档

PyTorch 的全面开发者文档

查看文档

教程

深入了解初学者和高级开发者的教程

查看教程

资源

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

查看资源