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

Some intersting functions of torch

5 of some basic and very useful functions

An short introduction about PyTorch and about the chosen functions.

  • torch.is_tensor()
  • torch.as_tensor()
  • torch.zeros_like()
  • torch.arange()
  • torch.randn()
# Import torch and other required modules
import torch

Function 1 - torch.is_tensor()

Returns True if obj is a PyTorch tensor.

# Example 1 - working (change this)
x = torch.tensor([[1, 2], [3, 4.]])
torch.is_tensor(x)
True

Here x was a tensor created and the function returned True.