评价此页

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