|
1 | 1 | --- |
2 | 2 | Title: 'round.()' |
3 | | -Description: 'Rounds each element to the nearest integer or specified number of decimals. |
| 3 | +Description: 'Rounds each element to the nearest integer or specified number of decimals.' |
4 | 4 | Subjects: |
5 | | - - 'Computer Science' |
6 | | - - 'Machine Learning' |
7 | | - - 'Data Science' |
| 5 | + - 'Computer Science' |
| 6 | + - 'Machine Learning' |
| 7 | + - 'Data Science' |
8 | 8 | Tags: |
9 | | - - 'Round' |
10 | | - - 'Python' |
11 | | - - 'Tensor' |
12 | | - - 'Computer Science' |
13 | | -Catalog Content: |
14 | | - - 'intro-to-py-torch-and-neural-networks' |
15 | | - - 'paths/computer-science' |
16 | | - - 'paths/machine-learning' |
17 | | - - 'paths/data-science |
| 9 | + - 'Round' |
| 10 | + - 'Python' |
| 11 | + - 'Tensor' |
| 12 | + - 'Computer Science' |
| 13 | +CatalogContent: |
| 14 | + - 'intro-to-py-torch-and-neural-networks' |
| 15 | + - 'paths/computer-science' |
| 16 | + - 'paths/machine-learning' |
| 17 | + - 'paths/data-science' |
18 | 18 | --- |
19 | 19 |
|
20 | | -In PyTorch, the **'.round'** function returns a new [tensor](https://docs.pytorch.org/docs/stable/generated/torch.round.html#torch.round) rounded to the nearest integer. |
| 20 | +In PyTorch, the **`.round`** function returns a new [tensor](https://docs.pytorch.org/docs/stable/generated/torch.round.html#torch.round) rounded to the nearest integer. |
21 | 21 |
|
22 | 22 | ## Syntax |
23 | 23 |
|
24 | | -```torch.round(input, decimals=0) |
25 | 24 | ``` |
| 25 | +torch.round(input, decimals=0) |
| 26 | +``` |
| 27 | + |
26 | 28 | - `input`: (tensor) the input tensor to be rounded. |
27 | 29 | - `decimals`: (int) Number of decimal places to round to (default: 0). If decimals is negative, it specifies the number of positions to the left of the decimal point. |
28 | 30 |
|
29 | 31 | ## Examples |
30 | 32 |
|
| 33 | +```python |
31 | 34 | torch.round(torch.tensor((4.7, -2.3, 9.1, -7.7))) |
32 | 35 |
|
33 | 36 | # Values equidistant from two integers are rounded towards the |
34 | | -# the nearest even value (zero is treated as even) |
| 37 | +# the nearest even value (zero is treated as even) |
35 | 38 | torch.round(torch.tensor([-0.5, 0.5, 1.5, 2.5])) |
36 | 39 |
|
37 | 40 | # A positive decimals argument rounds to the to that decimal place |
38 | 41 | torch.round(torch.tensor([0.1234567]), decimals=3) |
39 | 42 |
|
40 | 43 | # A negative decimals argument rounds to the left of the decimal |
41 | | -torch.round(torch.tensor([1200.1234567]), decimals=-3) |
| 44 | +torch.round(torch.tensor([1200.1234567]), decimals=-3) |
| 45 | +``` |
0 commit comments