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

Five Pytorch Tensor Functions

Exporing how they work

PyTorch is an open source machine learning library based on the Torch library, used for applications such as computer vision and natural language processing, primarily developed by Facebook's AI Research lab

# Import torch and other required modules
import torch

Function 1 - torch.equal(input, other) → bool

This function takes two tensors as input. It returns True if they have the same size and elements and False otherwise

# Example 1 - Works
t1 = torch.tensor([[1, 2], 
              [3, 4.]])
t2 = torch.tensor([[1, 2], 
              [3, 4.]])

torch.equal(t1, t2)
True

When the two tensors have the same size and elements