1. torch.floor(input, out=None)
說明:牀函數,返回一個新張量,包含輸入input張量每個元素的floor,即不小於元素的最大整數。
參數:
- input(Tensor) -- 輸入張量
- out(Tenosr, 可選) -- 輸出張量
>>> a = torch.randn(4)
>>> torch.floor(a)
tensor([ 0., -1., 1., 0.])
2. torch.fmod(input, divisor, out=None)
說明:計算除法餘數。除數與被除數可能同時含有整數和浮點數。此時,餘數的正負與被除數相同
參數:
- input(Tensor) -- 被除數
- divisor(Tensor或float) -- 除數,一個數或與被除數相同類型的張量
- out(Tensor,可選) -- 輸出張量
>>> torch.fmod(torch.Tensor([-3, -2, -1, 1, 2, 3]), 2)
tensor([-1., -0., -1., 1., 0., 1.])
>>> torch.fmod(torch.Tensor([1, 2, 3, 4, 5]), 1.5)
tensor([1.0000, 0.5000, 0.0000, 1.0000, 0.5000])
3. torch.frac(tensor, out=None)
說明:返回每個元素的分數部分
參數:
- tensor(Tensor) -- 輸入張量,可以是小數也可是整數
- out(Tensor,可選) -- 輸出張量
>>> torch.frac(torch.Tensor([1, 2.3, -3.2]))
tensor([ 0.0000, 0.3000, -0.2000])
4. torch.lerp(start, end, weight, out=None)
說明:對兩個張量以start,end做線性插值,將結果返回到輸出張量。即out = start + weight * (end - start).
參數:
- start(Tensor) -- 起始點張量
- end(Tensor) -- 終止點張量
- weight(float) -- 插值公式的weight
- out(Tensor,可選) -- 結果張量
>>> start = torch.arange(1., 5.)
>>> end = torch.empty(4).fill_(10)
>>> start
tensor([1., 2., 3., 4.])
>>> end
tensor([10., 10., 10., 10.])
>>> torch.lerp(start, end, 0.5)
tensor([5.5000, 6.0000, 6.5000, 7.0000])
5. torch.log(input, out=None)
說明:計算input的自然對數
參數:
- input(Tensor) -- 輸入張量
- out(Tensor, 可選) -- 輸出張量
>>> a = torch.randn(5)
>>> a
tensor([-1.1601, -0.8747, 0.2048, 1.8377, 0.2801])
>>> torch.log(a)
tensor([ nan, nan, -1.5856, 0.6085, -1.2725])
6. torch.log1p(input, out=None)
說明:計算input+1的自然對數,對值比較小的輸入,此函數比torch.log()更準確
參數:
- input(Tensor) -- 輸入張量
- out(Tensor,可選) -- 輸出張量
>>> a = torch.randn(6)
>>> a
tensor([ 0.4177, 0.7744, -1.8840, 0.3302, 1.7383, -0.1667])
>>> torch.log1p(a)
tensor([ 0.3490, 0.5735, nan, 0.2854, 1.0073, -0.1824])
7. torch.mul(input, value, out=None)
說明:用標量值value乘以輸入input的每個元素,並返回一個新的結果張量。out = tensor * value
參數:
- input(Tensor) -- 輸入張量
- value(Number) -- 乘到每個元素的數
- out(Tensor,可選) -- 輸出張量
>>> a = torch.randn(4)
>>> a
tensor([-1.7720, -0.8593, -0.0354, -0.0747])
>>> torch.mul(a, 100)
tensor([-177.2037, -85.9287, -3.5436, -7.4714])
8. torch.mul(input, other, out=None)
說明:兩個張量input,other按元素進行相乘,並返回輸出張量
參數:
- input(Tensor) -- 第一個相乘張量
- other(Tensor) -- 第二個相乘張量
- out(Tensor,可選) -- 結果張量
>>> a = torch.randn(4, 4)
>>> b = torch.randn(4, 4)
>>> torch.mul(a, b)
tensor([[ 0.1404, -0.3859, 1.9077, 0.7873],
[-1.5376, -0.7447, 1.6224, -0.3152],
[-0.0610, 0.2805, -0.0194, 0.4091],
[-0.0842, 0.1382, -0.1696, 0.0576]])
9. torch.neg(input, out=None)
說明:返回一個新張量,包含輸入input張量按元素取負。out = -1 * input
參數:
- input(Tensor) -- 輸入張量
- out(Tensor, 可選) -- 輸出張量
>>> a = torch.randn(5)
>>> a
tensor([ 0.8791, -0.5795, -1.1354, 0.4425, -0.1631])
>>> torch.neg(a)
tensor([-0.8791, 0.5795, 1.1354, -0.4425, 0.1631])
10. torch.pow(input, exponent, out=None)
說明:對輸入input按元素求exponent次冪值,並返回結果張量,冪值exponent可以爲標量也可以是和input相同大小的張量。
參數:
- input(Tensor) -- 輸入張量
- exponent(float or Tensor) -- 冪值
- out(Tensor, 可選) -- 輸出張量
>>> a = torch.randn(4)
>>> a
tensor([-0.2202, 0.0814, -0.0079, -0.7530])
>>> torch.pow(a, 2)
tensor([4.8492e-02, 6.6341e-03, 6.1897e-05, 5.6697e-01])
11. torch.pow(base, input, out=None)
說明:base爲標量浮點值,input爲張量,返回的輸出張量out與輸出張量相同形狀。執行操作
參數:
- base(float) -- 標量值,指數的底
- input(Tensor) -- 冪值
- out(Tensor, 可選) -- 輸出張量
>>> exp = torch.arange(1, 5)
>>> base = 2
>>> torch.pow(base, exp)
tensor([ 2, 4, 8, 16])