torch.float_power¶
- torch.float_power(input, exponent, *, out=None) Tensor ¶
以雙精度方式,逐元素地將
input
提高到exponent
的冪次方。如果輸入都不是複數,則傳回一個torch.float64
張量;如果一個或多個輸入是複數,則傳回一個torch.complex128
張量。注意
與
torch.pow()
不同,此函數總是使用雙精度計算,torch.pow()
實現了更典型的 類型提升。當計算需要在更寬或更精確的 dtype 中執行,或者計算結果可能包含輸入 dtype 無法表示的分數值時,這非常有用,例如當整數底數被提升為負整數指數時。- 參數
- 關鍵字參數
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)