評價此頁

torch.float_power#

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

input 逐元素地以雙精度提升到 exponent 的冪。如果兩個輸入都不是複數,則返回一個 torch.float64 張量;如果一個或多個輸入是複數,則返回一個 torch.complex128 張量。

注意

此函式始終以雙精度進行計算,這與 torch.pow() 不同,後者實現了更典型的 型別提升。當需要以更寬或更精確的資料型別執行計算,或者計算結果可能包含輸入資料型別無法表示的分數(例如,當整數基數提升到負整數指數時)時,此函式非常有用。

引數
  • input (TensorNumber) – 基數

  • exponent (TensorNumber) – 指數

關鍵字引數

out (Tensor, optional) – 輸出張量。

示例

>>> 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)