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