Skip to content

Commit 1a3c4a9

Browse files
[Term Entry] PyTorch Tensor Operations: .bitwise_not()
* Add entry for pytorch bitwise not * minor fixes * Update bitwise-not.md ---------
1 parent efa172e commit 1a3c4a9

File tree

1 file changed

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

1 file changed

+54
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
---
2+
Title: '.bitwise_not()'
3+
Description: 'Performs element-wise bitwise NOT operation on the input tensor, flipping each bit (0 to 1 and 1 to 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](https://www.codecademy.com/resources/docs/pytorch/tensors). 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+
**Parameters:**
26+
27+
- `input`: A tensor of integer or boolean dtype.
28+
- `out` (Optional): A tensor for storing the output result. Must have the same shape as the input tensor.
29+
30+
**Return value:**
31+
32+
The `.bitwise_not()` function returns a new tensor containing the result of applying the bitwise NOT operation to each element in the input tensor.
33+
34+
## Example
35+
36+
The following example illustrates the usage of the `.bitwise_not()` function in PyTorch:
37+
38+
```py
39+
import torch
40+
41+
# Create a boolean tensor
42+
tensor_in = torch.tensor([True, False, True])
43+
44+
# Apply bitwise NOT
45+
result = torch.bitwise_not(tensor_in)
46+
47+
print(result)
48+
```
49+
50+
The above code produces the following output:
51+
52+
```shell
53+
tensor([False, True, False])
54+
```

0 commit comments

Comments
 (0)