You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: content/pytorch/concepts/tensor-operations/terms/logical-or/logical-or.md
+9-9Lines changed: 9 additions & 9 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -13,7 +13,7 @@ CatalogContent:
13
13
- 'paths/data-science'
14
14
---
15
15
16
-
The **`.logical_or()`** function performs an element-wise logical OR operation between two [tensors](https://www.codecademy.com/resources/docs/pytorch/tensors). The result contains Boolean values where each element is `True` if either corresponding element in the inputs evaluates to non-zero. Inputs are interpreted as Boolean: zero values are considered `False`, and non-zero values are considered`True`.
16
+
The **`.logical_or()`** function performs an element-wise logical OR operation between two [tensors](https://www.codecademy.com/resources/docs/pytorch/tensors). Each input value is converted to a Boolean value (zero → `False`, non-zero → `True`) before the operation. The output is a Boolean tensor where each element is `True` if at least one of the corresponding input elements is`True`.
Returns a Boolean tensor where each position is `True` if either corresponding element in the inputs evaluates as`True`.
32
+
Returns a Boolean tensor where each element is `True` if at least one of the corresponding input elements is`True`.
33
33
34
34
## Example 1
35
35
@@ -52,16 +52,16 @@ The output of this code is:
52
52
53
53
```shell
54
54
Tensor A:
55
-
tensor([[0, 1],
55
+
tensor([[0, 1],
56
56
[2, 0]])
57
57
58
58
Tensor B:
59
-
tensor([[3, 0],
59
+
tensor([[3, 0],
60
60
[0, 5]])
61
61
62
62
A OR B:
63
-
tensor([[True, True],
64
-
[True, True]])
63
+
tensor([[True, True],
64
+
[True, True]])
65
65
```
66
66
67
67
## Example 2
@@ -82,19 +82,19 @@ print(result)
82
82
The output of this code is:
83
83
84
84
```shell
85
-
tensor([True, True, True, True])
85
+
tensor([True, True, True, True])
86
86
```
87
87
88
88
## Frequently Asked Questions
89
89
90
90
### 1. What are the tensor operations in PyTorch?
91
91
92
-
Tensor operations include arithmetic, logical operations, reductions, reshaping, indexing, broadcasting, and matrix operations. These operations run efficiently on CPU or GPU and form the core building blocks of neural network workflows.
92
+
Tensor operations in PyTorch include arithmetic, logical operations, reductions, reshaping, indexing, broadcasting, and matrix operations. These operations run efficiently on CPU or GPU and form the core building blocks of neural network workflows.
93
93
94
94
### 2. Why use tensor instead of NumPy?
95
95
96
96
Tensors support automatic differentiation and execute seamlessly on GPUs, which makes them suited for deep learning workloads. They also integrate tightly with PyTorch's computation graph, while NumPy arrays operate only on the CPU and lack gradient support.
97
97
98
-
### 3. What does CPU() do in PyTorch?
98
+
### 3. What does cpu() do in PyTorch?
99
99
100
100
The `.cpu()` method moves a tensor or model from a GPU device to the system’s CPU. This is useful for running operations on hardware without CUDA support or preparing data for libraries that operate only on CPU-based arrays.
0 commit comments