Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 3f9a029

Browse files
committedApr 4, 2025·
Add entry for pytorch bitwise not
1 parent 778865c commit 3f9a029

File tree

1 file changed

+48
-0
lines changed
  • content/pytorch/concepts/tensor-operations/terms/bitwise-not

1 file changed

+48
-0
lines changed
 
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
---
2+
Title: '.bitwise_not()'
3+
Description: 'Performs element-wise bitwise NOT operation on the input tensor, flipping each bit (0 becomes 1 and 1 becomes 0). Applicable to integer and boolean tensors.'
4+
Subjects:
5+
- 'AI'
6+
- 'Data Science'
7+
Tags:
8+
- 'AI'
9+
- 'Data Types'
10+
- 'Deep Learning'
11+
- 'Functions'
12+
CatalogContent:
13+
- 'intro-to-py-torch-and-neural-networks'
14+
- 'paths/data-science'
15+
---
16+
17+
In PyTorch, the **`.bitwise_not()`** function performs an element-wise bitwise NOT operation on the input tensor. This flips each bit of the tensor’s binary representation, turning `0` to `1` and `1` to `0`. It works for integer tensors (signed or unsigned) and boolean tensors (where it acts as a logical NOT).
18+
19+
## Syntax
20+
21+
```pseudo
22+
torch.bitwise_not(input, *, out=None)
23+
```
24+
25+
- `input`: A tensor of integer or boolean dtype.
26+
- `out` (Optional): The output tensor to store the result.
27+
28+
## Example
29+
30+
The following example demonstrates the usage of the `.bitwise_not()` function:
31+
32+
```py
33+
import torch
34+
35+
# Create a boolean tensor
36+
tensor_in = torch.tensor([True, False, True])
37+
38+
# Apply bitwise NOT
39+
result = torch.bitwise_not(tensor_in)
40+
41+
print(result)
42+
```
43+
44+
The above code produces the following output:
45+
46+
```shell
47+
tensor([False, True, False])
48+
```

0 commit comments

Comments
 (0)
Please sign in to comment.