Learn practical skills, build real-world projects, and advance your career
Updated 3 years ago
A quick overview of PyTorch
An short introduction about PyTorch and about the chosen functions.
torch.tensor()
torch.t()
torch.chunk()
torch.cat()
torch.inverse()
Before we begin, let's install and import PyTorch
# 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
Function 1 - torch.tensor()
torch.tensor()
is used to create a tensor. It can create scalars (0-D tensors), vectors (1-D tensors), matrices (2-D tensors) and N-D tensors.
# Example 1 - create a matrix (2-D tensor)
torch.tensor([[3, 1], [2., 4.]])
tensor([[3., 1.],
[2., 4.]])