捷徑

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.])

文件

存取 PyTorch 的完整開發者文件

檢視文件

教學課程

取得針對初學者和進階開發者的深度教學課程

檢視教學課程

資源

尋找開發資源並取得問題解答

檢視資源