Fonction torch.round de PyTorch
Manuel de référence Pytorch torch
torch.roundIl s'agit d'une fonction de PyTorch pour l'arrondi élément par élément.
Définition de fonction
torch.round(input, decimals, out)
Exemple d'utilisation
Exemple
import torch
x = torch.tensor([0.1, 0.5, 0.9, 1.2, 1.5])
print(torch.round(x))
# Spécifier le nombre de décimales
y = torch.tensor([1.234, 5.678])
print(torch.round(y, decimals=2))
x = torch.tensor([0.1, 0.5, 0.9, 1.2, 1.5])
print(torch.round(x))
# Spécifier le nombre de décimales
y = torch.tensor([1.234, 5.678])
print(torch.round(y, decimals=2))
Le résultat de sortie est:
tensor([0., 0., 1., 1., 2.]) tensor([1.2300, 5.6800])
Autres extensions