快捷方式

torch.pow

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

計算 input 中每個元素的 exponent 次冪,並返回結果張量。

exponent 可以是單個 float 數,也可以是與 input 元素數量相同的 Tensor

exponent 是一個標量值時,應用的操作是

outi=xiexponent\text{out}_i = x_i ^ \text{exponent}

exponent 是一個張量時,應用的操作是

outi=xiexponenti\text{out}_i = x_i ^ {\text{exponent}_i}

exponent 是一個張量時,inputexponent 的形狀必須是 可廣播的

引數
  • input (Tensor) – 輸入張量。

  • exponent (float張量) – 指數的值

關鍵字引數

out (Tensor, 可選) – 輸出張量。

示例

>>> a = torch.randn(4)
>>> a
tensor([ 0.4331,  1.2475,  0.6834, -0.2791])
>>> torch.pow(a, 2)
tensor([ 0.1875,  1.5561,  0.4670,  0.0779])
>>> exp = torch.arange(1., 5.)

>>> a = torch.arange(1., 5.)
>>> a
tensor([ 1.,  2.,  3.,  4.])
>>> exp
tensor([ 1.,  2.,  3.,  4.])
>>> torch.pow(a, exp)
tensor([   1.,    4.,   27.,  256.])
torch.pow(self, exponent, *, out=None) Tensor

self 是一個標量 float 值,而 exponent 是一個張量。返回的張量 out 的形狀與 exponent 相同

應用的操作是

outi=selfexponenti\text{out}_i = \text{self} ^ {\text{exponent}_i}
引數
  • self (float) – 冪運算的標量底值

  • exponent (Tensor) – 指數張量

關鍵字引數

out (Tensor, 可選) – 輸出張量。

示例

>>> exp = torch.arange(1., 5.)
>>> base = 2
>>> torch.pow(base, exp)
tensor([  2.,   4.,   8.,  16.])

文件

訪問 PyTorch 的全面開發者文件

檢視文件

教程

獲取針對初學者和高階開發者的深度教程

檢視教程

資源

查詢開發資源並獲得問題解答

檢視資源