PyTorch torch.trunc 函数

约 216 字 更新于 2026-11-18 5iyo.com

PyTorch torch.trunc 函数


torch.trunc 是 PyTorch 中用于逐元素截断(取整数部分)的函数。

函数定义

torch.trunc(input, out=None)

使用示例

实例

import torch

# 逐元素截断
x = torch.tensor([1.5, 2.7, -3.3])
result = torch.trunc(x)
print(result)