torch.pow#
- torch.pow(input, exponent, *, out=None) Tensor#
計算
input中每個元素以exponent為指數的冪,並返回結果張量。exponent可以是單個float數值,也可以是與input具有相同元素數量的 Tensor。當
exponent是標量值時,應用的操作是:當
exponent是張量時,應用的操作是:當
exponent是張量時,input和exponent的形狀必須是 可廣播的。示例
>>> 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相同。應用的操作是:
示例
>>> exp = torch.arange(1., 5.) >>> base = 2 >>> torch.pow(base, exp) tensor([ 2., 4., 8., 16.])