How to compare two tensors in PyTorch?
In this article, we are going to see how we can compare two tensors in Pytorch.
We can compare two tensors by using the torch.eq() method. This method compares the corresponding elements of tensors. It has to return rue at each location where both tensors have equal value else it will return false.
Syntax: torch.eq( First_tensor, Second_tensor, out=None )
Parameters: torch.eq() accept tensors that are we want to compare as parameters.
Return: It return a boolean value. true if tensors are equals else it will return false.
In this example, we are comparing two 1-D tensors using the torch.eq() function in the python programming language .
Under this example, we are comparing 2D tensors PyTorch using the torch.eq() function.
Please Login to comment...