Learn practical skills, build real-world projects, and advance your career
Updated 3 years ago
Some simple and useful Pytorch functions
In this notebook I'll describe some useful Pytorch functions.
- torch.rand()
- torch.arange()
- torch.transpose()
- torch.chunk()
- torch.inverse()
Before we begin, let's install and import PyTorch
# Import torch and other required modules
import torch
Function 1 - torch.rand()
Returns a tensor filled with random numbers from a uniform distribution on the interval [0, 1)[0,1)
The shape of the tensor is defined by the variable argument size.
# Example 1 -
torch.rand(4)
tensor([0.6374, 0.3765, 0.8984, 0.5408])
In this example we use the torch.rand () function to create a one-dimensional tensor with 4 random elements between 0 to 1.