Skip to content

Commit 9b1798b

Browse files
[Term Entry] PyTorch Tensor Operations: .floor_divide() (#7472)
* Create floor-divide.md * minor tweaks * Update content/pytorch/concepts/tensor-operations/terms/floor-divide/floor-divide.md * Update content/pytorch/concepts/tensor-operations/terms/floor-divide/floor-divide.md ---------
1 parent 5fcb2bc commit 9b1798b

File tree

1 file changed

+55
-0
lines changed
  • content/pytorch/concepts/tensor-operations/terms/floor-divide

1 file changed

+55
-0
lines changed
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
---
2+
Title: '.floor_divide()'
3+
Description: 'Computes element-wise division of tensors (or tensor and scalar) and applies floor rounding.'
4+
Subjects:
5+
- 'Computer Science'
6+
- 'Machine Learning'
7+
Tags:
8+
- 'Functions'
9+
- 'Machine Learning'
10+
- 'Python'
11+
- 'Tensor'
12+
CatalogContent:
13+
- 'intro-to-py-torch-and-neural-networks'
14+
- 'paths/computer-science'
15+
---
16+
17+
In PyTorch, the **`.floor_divide()`** function divides the `input` by other element-wise and rounds each quotient down to the nearest integer, returning the floored result as a [tensor](https://www.codecademy.com/resources/docs/pytorch/tensors). It supports broadcasting, type promotion, and both integer and floating-point operands. The operation can be expressed as:
18+
19+
$$\text{out}_i = \text{floor}(\frac{\text{input}_i}{\text{other}_i})$$
20+
21+
## Syntax
22+
23+
```pseudo
24+
torch.floor_divide(input, other, *, out=None) → Tensor
25+
```
26+
27+
**Parameters:**
28+
29+
- `input`: The input tensor(dividend).
30+
- `other`: Tensor or Number(divisor).
31+
- `out` (Optional): A tensor to store the output. If provided, the result is written to this tensor.
32+
33+
**Return value:**
34+
35+
It returns a new tensor of the same shape as the `input`, containing the result of element-wise division and rounds the result of the division down to the nearest integer.
36+
37+
## Example
38+
39+
In this example, we use `floor_divide()` to perform divison of two tensors `x` and `y` :
40+
41+
```py
42+
import torch
43+
44+
x = torch.tensor([4.0, 3.0])
45+
46+
y = torch.tensor([2.0, 2.0])
47+
48+
print(torch.floor_divide(x, y))
49+
```
50+
51+
The output of this code is:
52+
53+
```shell
54+
tensor([2., 1.])
55+
```

0 commit comments

Comments
 (0)