PyTorch torch.fix 函数
torch.fix 是 PyTorch 中用于逐元素取整数部分(向零取整)的函数。
函数定义
torch.fix(input, *, out=None)
使用示例
实例
import torch
# 取整数部分示例
x = torch.tensor([-1.5, -0.5, 0.5, 1.5, 2.7])
result = torch.fix(x)
print(result) # tensor([-1., -0., 0., 1., 2.])
# 取整数部分示例
x = torch.tensor([-1.5, -0.5, 0.5, 1.5, 2.7])
result = torch.fix(x)
print(result) # tensor([-1., -0., 0., 1., 2.])

Pytorch torch 参考手册