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

#Ajeya Krishna

5 essential Pytorch function you need to know

An short introduction about PyTorch and about the chosen functions.

  • torch.numel(tensor)
  • torch.randn(shape)
  • torch.addcmul(input,tensor1,tensor2,value)
  • torch.ceil(tensor)
  • torch.sigmoid(tensor)

Before we begin, let's install and import PyTorch

# Import torch and other required modules
import torch

Function 1 - torch.numel(tensor)

The torch.numel(tensor) function returns the length of the tensor. This funciton is independent of the shape or the dimensions of the tensor, it just counts the number of elements in the tensor. This function is handy and we have seen this function in usage in the first video lecture by aakash.

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