torch.float_power¶
- torch.float_power(input, exponent, *, out=None) Tensor ¶
Raises
input
to the power ofexponent
, elementwise, in double precision. If neither input is complex returns atorch.float64
tensor, and if one or more inputs is complex returns atorch.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)