Skip to content

Commit 85bae8d

Browse files
tensor operations round
1 parent 4832cb4 commit 85bae8d

File tree

1 file changed

+21
-17
lines changed
  • content/pytorch/concepts/tensor-operations/terms/round

1 file changed

+21
-17
lines changed
Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,45 @@
11
---
22
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.'
44
Subjects:
5-
- 'Computer Science'
6-
- 'Machine Learning'
7-
- 'Data Science'
5+
- 'Computer Science'
6+
- 'Machine Learning'
7+
- 'Data Science'
88
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'
1818
---
1919

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.
2121

2222
## Syntax
2323

24-
```torch.round(input, decimals=0)
2524
```
25+
torch.round(input, decimals=0)
26+
```
27+
2628
- `input`: (tensor) the input tensor to be rounded.
2729
- `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.
2830

2931
## Examples
3032

33+
```python
3134
torch.round(torch.tensor((4.7, -2.3, 9.1, -7.7)))
3235

3336
# 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)
3538
torch.round(torch.tensor([-0.5, 0.5, 1.5, 2.5]))
3639

3740
# A positive decimals argument rounds to the to that decimal place
3841
torch.round(torch.tensor([0.1234567]), decimals=3)
3942

4043
# 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

Comments
 (0)