Learn practical skills, build real-world projects, and advance your career
Created 3 years ago
# Uncomment and run the appropriate command for your operating system, if required
# Linux / Binder
# !pip install numpy torch==1.7.0+cpu torchvision==0.8.1+cpu torchaudio==0.7.0 -f https://download.pytorch.org/whl/torch_stable.html
# Windows
!pip install numpy torch==1.7.0+cpu torchvision==0.8.1+cpu torchaudio==0.7.0 -f https://download.pytorch.org/whl/torch_stable.html
# MacOS
# !pip install numpy torch torchvision torchaudio
# Import torch and other required modules
import torch
5 useful PyTorch functions you need to know as a data scientist
An short introduction about PyTorch and about the chosen functions.
- torch.rand()
- torch.mean()
- torch.view()
- function 4
- function 5
Before we begin, let's install and import PyTorch
Function 1 - torch.rand()
This function returns a tensor filled with random numbers from a normal distribution on the interval [0,1).
It takes the following arguments:
- size(int) - to define shape of output tensor
- dtype(torch.dtype, optional) - to define the datatype of returned tensor
- requires_grad(bool, optional) - to allow autograd to record operations on the returned tensor
# Example 1 - working example
torch.rand(9)