Learn practical skills, build real-world projects, and advance your career
# 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
Looking in links: https://download.pytorch.org/whl/torch_stable.html Requirement already satisfied: numpy in /usr/local/lib/python3.6/dist-packages (1.19.5) Requirement already satisfied: torch==1.7.0+cpu in /usr/local/lib/python3.6/dist-packages (1.7.0+cpu) Requirement already satisfied: torchvision==0.8.1+cpu in /usr/local/lib/python3.6/dist-packages (0.8.1+cpu) Requirement already satisfied: torchaudio==0.7.0 in /usr/local/lib/python3.6/dist-packages (0.7.0) Requirement already satisfied: future in /usr/local/lib/python3.6/dist-packages (from torch==1.7.0+cpu) (0.16.0) Requirement already satisfied: dataclasses in /usr/local/lib/python3.6/dist-packages (from torch==1.7.0+cpu) (0.8) Requirement already satisfied: typing-extensions in /usr/local/lib/python3.6/dist-packages (from torch==1.7.0+cpu) (3.7.4.3) Requirement already satisfied: pillow>=4.1.1 in /usr/local/lib/python3.6/dist-packages (from torchvision==0.8.1+cpu) (7.0.0)

Torch Functions

An short introduction about PyTorch and about the chosen functions.

1:. torch.linspace()

2:. torch.view()

3:. torch stack .>>torch.hstack() .>>torch.dstack()

4:. torch.eq()

5:. torch.max()

Before we begin, let's install and import PyTorch

# Import torch and other required modules
import torch

Function 1 - torch.linspace (start, end, step)

torch.linspace(start, end, steps, *, out=None, dtype=None, layout=torch.strided, device=None, requires_grad=False) → Tensor

Creates a one-dimensional tensor of size steps whose values are evenly spaced from start to end, inclusive.

# Example 1 - working
torch.linspace(1,50,30)
tensor([ 1.0000,  2.6897,  4.3793,  6.0690,  7.7586,  9.4483, 11.1379, 12.8276,
        14.5172, 16.2069, 17.8966, 19.5862, 21.2759, 22.9655, 24.6552, 26.3448,
        28.0345, 29.7241, 31.4138, 33.1034, 34.7931, 36.4828, 38.1724, 39.8621,
        41.5517, 43.2414, 44.9310, 46.6207, 48.3103, 50.0000])