Learn practical skills, build real-world projects, and advance your career
Updated 3 years ago
#Some functions of Pytorch, the deep learning python library
An short introduction about PyTorch and about the chosen functions.
- torch.narrow
- torch.polar
- torch.split
- torch.reshape
- torch.abs
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
import numpy as np #will be useful in examples
Function 1 - torch.narrow
It returns a narrowed version of the given input tensor.
a = torch.tensor([[[1, 2, 3], [3, 4., 5]], [[6, 7, 9],[34, 5,8]],[[21, 67, 10], [34, 11,15]]])
a.shape
#Now we pass this tensor to the narrow function
torch.Size([3, 2, 3])