Compute element-wise with logical NOT
torch.logical_not() – This method is used to compute the element-wise logical NOT of the given input tensor. This method also treated the non-zero values as True and zero values as False. The following syntax is used to compute logical NOT.
Syntax – torch.logical_not(input)
Parameter –
- input – This is our input tensor
Return –This method returns a tensor with values we get after computing the logical NOT.
The following program is to understand how to compute element-wise logical NOT of tensor.
Python3
# import required library import torch # create two tensors tens_1 = torch.tensor([ 11 , 0 ]) # display the tensors print ( "\n Input Tensor 1: \n" , tens_1) # compute the logical NOT tens = torch.logical_not(tens_1) # display result print ( "\n After Compute Logical NOT: \n" , tens) |
Output:
Compute element-wise logical AND, OR and NOT of tensors in PyTorch
In this article, we are going to see how to compute element-wise logical AND, OR, and NOT of given tensors in PyTorch. We can compute this by using the torch.logical_and(), torch.logical_or(), and torch.logical_not() methods. Let’s discuss all of them one by one.