PyTorch torch.round 関数


Pytorch torch 参考手册Pytorch torch リファレンスマニュアル

torch.roundPyTorch で要素ごとに四捨五入する関数です。

関数定義

torch.round(input, decimals, out)

使用例

実例

import torch

x = torch.tensor([0.1, 0.5, 0.9, 1.2, 1.5])

print(torch.round(x))

# 小数点以下の桁数を指定
y = torch.tensor([1.234, 5.678])
print(torch.round(y, decimals=2))

出力結果は:

tensor([0., 0., 1., 1., 2.])
tensor([1.2300, 5.6800])

Pytorch torch 参考手册Pytorch torch リファレンスマニュアル

その他の拡張