評價此頁

torch.trunc#

torch.trunc(input, *, out=None) Tensor#

返回一個新張量,其中包含input元素的截斷整數值。

對於整數輸入,遵循 array-api 約定,返回輸入張量的副本。

引數

input (Tensor) – 輸入張量。

關鍵字引數

out (Tensor, optional) – 輸出張量。

示例

>>> a = torch.randn(4)
>>> a
tensor([ 3.4742,  0.5466, -0.8008, -0.9079])
>>> torch.trunc(a)
tensor([ 3.,  0., -0., -0.])