Learn practical skills, build real-world projects, and advance your career
Created 3 years ago
First 5 things to start learning PyTorch Tensors
lets begin our TorchAdventure! with this 11 basic functions distributed in the following sections:
- Creating tensors: Empty() and Zeros()
- measuring tensors: Size() and Shape(), Sum() and Dimensions
- changing and copying tensors: Reshape(), view() and randm()
- modifying tensors: Unsqueeze()
- comparing tensors: Element-Wise Equality: Eq
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 - Empty and Zeros - how to initialize tensors
We need to start workng with the basics pytorch functions, and the first thing is create our matrix
# Creates a 3 x 2 matrix which is empty
a = torch.empty(3, 2)
print(a)
tensor([[1.5842e-35, 0.0000e+00],
[4.4842e-44, 0.0000e+00],
[ nan, 0.0000e+00]])