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

Basic Tensor Operations

basic understanding of some of the most used tensor operations

An short introduction about PyTorch and about the chosen functions.

  • torch.numel
  • torch.arange
  • torch.cat
  • torch.reshape
  • torch.add
# Import torch and other required modules
import torch

Function 1 - torch.numel

Returns the total number of elements in the input tensor.

# Example 1 - working (change this)
a = torch.ones([1, 2])
torch.numel(a)
2

torch.numel returns the total number of elements in a given torch.ones(returns just 1s in a specified shape) tensor.