torch.trunc torch.trunc(input, *, out=None) → Tensor 返回一个新的张量,包含input元素的截断整数值。 对于整数输入,按照array-api规范返回输入张量的副本。 参数 input (Tensor) – 需要输入的张量。 关键字参数 out (Tensor, 可选) – 指定输出张量。 示例: >>> a = torch.randn(4) >>> a tensor([ 3.4742, 0.5466, -0.8008, -0.9079]) >>> torch.trunc(a) tensor([ 3., 0., -0., -0.])