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

assignment 1 :

Top 5 Pytorch functions you should have to know

An short introduction about PyTorch and about the chosen functions.

  • torch.rand() : Returns a tensor filled with random numbers from a uniform distribution on the interval(0,1).
  • torch.randint() : Returns a tensor filled with random integers generated uniformly between low and high .
  • torch.randperm(): Returns a random permutation of integers from 0 to n - 1.
  • torch.numel() : Returns a number of elemnts in an input tensor .
  • torch.empthy() : Returns a tensor filled with uninitialized data.
# Import torch and other required modules
import torch

Function 1 - torch.rand(*size, out=None, dtype=None, layout=torch.strided, device=None, requires_grad=False) → Tensor

Returns a tensor filled with a random numbers from a uniform distribution on the interval [0, 1)[0,1)

# Example 1 - working 
torch.rand(4)
tensor([0.8082, 0.9993, 0.2175, 0.0240])

it's filled with 4 random on the interval 0,1