Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Term Entry] PyTorch Tensor Operations: .bitwise_not() #6479

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
---
Title: '.bitwise_not()'
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.'
Subjects:
- 'AI'
- 'Data Science'
Tags:
- 'AI'
- 'Data Types'
- 'Deep Learning'
- 'Functions'
CatalogContent:
- 'intro-to-py-torch-and-neural-networks'
- 'paths/data-science'
---

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

## Syntax

```pseudo
torch.bitwise_not(input, *, out=None)
```

- `input`: A tensor of integer or boolean dtype.
- `out` (Optional): The output tensor to store the result.

## Example

The following example demonstrates the usage of the `.bitwise_not()` function:

```py
import torch

# Create a boolean tensor
tensor_in = torch.tensor([True, False, True])

# Apply bitwise NOT
result = torch.bitwise_not(tensor_in)

print(result)
```

The above code produces the following output:

```shell
tensor([False, True, False])
```