Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

PyTorch torch.round function

PyTorch torch.round function


PyTorch torch reference manual PyTorch torch reference manual

torch.round is a function in PyTorch used to round elements to the nearest integer.

Function definition

torch.round(input, decimals, out)


Usage examples

Example

import

torch

x

=

torch.

tensor

(

[

0.1

,

0.5

,

0.9

,

1.2

,

1.5

]

)

print

(

torch.

round

(

x

)

)

Specify the number of decimal places

y

=

torch.

tensor

(

[

1.234

,

5.678

]

)

print

(

torch.

round

(

y

,

decimals

=

2

)

)

The output is:

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

tensor([1.2300, 5.6800])


PyTorch torch reference manual PyTorch torch reference manual