Learn practical skills, build real-world projects, and advance your career

Some functions to use Boolean tensors in PyTorch

One type of tensor supported by Pytorch is Boolean. While not necessarely interesting for regression, it can be useful to manipulate data before and after processing, here are a few examples.

# If necessary, uncomment the next line to install the requirements.
# !pip install numpy==1.18.5 torch==1.7.0+cpu torchvision==0.8.1+cpu torchaudio==0.7.0 -f https://download.pytorch.org/whl/torch_stable.html
import torch

Boolean functions

Pytorch supports the standard Boolean operations ==, !=, <, >, >=, <= elementwise for a tensor with a scalar or two tensors of the same size, returning a Boolean tensor with the result of each element-wise operation.