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

torch.float_power

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

Raises input to the power of exponent, elementwise, in double precision. If neither input is complex returns a torch.float64 tensor, and if one or more inputs is complex returns a torch.complex128 tensor.

注意

此函数始终以双精度计算,与 torch.pow() 不同,它实现了更典型的类型提升。这在需要以更宽或更精确的数据类型执行计算时很有用,或者计算结果可能包含在输入数据类型中无法表示的分数值时,例如当以整数为基础的指数为负整数时。

参数:
  • 输入(张量或数字)- 底数值

  • 指数(张量或数字)- 指数值

关键字参数:

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

示例:

>>> a = torch.randint(10, (4,))
>>> a
tensor([6, 4, 7, 1])
>>> torch.float_power(a, 2)
tensor([36., 16., 49.,  1.], dtype=torch.float64)

>>> a = torch.arange(1, 5)
>>> a
tensor([ 1,  2,  3,  4])
>>> exp = torch.tensor([2, -3, 4, -5])
>>> exp
tensor([ 2, -3,  4, -5])
>>> torch.float_power(a, exp)
tensor([1.0000e+00, 1.2500e-01, 8.1000e+01, 9.7656e-04], dtype=torch.float64)

© 版权所有 PyTorch 贡献者。

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

文档

PyTorch 的全面开发者文档

查看文档

教程

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

查看教程

资源

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

查看资源