Learn practical skills, build real-world projects, and advance your career

Jovian Notebook 1

An short introduction about PyTorch and about the chosen functions.

  • torch.range
  • torch.randint
  • torch.transpose
  • torch.hstack
  • torch.split

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.range

Returns a 1-D tensor of size
(end−start + 1) with values from start to end with step step. Step is the gap between two values in the tensor.

# Example 1 
torch.range(5,25,4)
/usr/local/lib/python3.7/dist-packages/ipykernel_launcher.py:2: UserWarning: torch.range is deprecated and will be removed in a future release because its behavior is inconsistent with Python's range builtin. Instead, use torch.arange, which produces values in [start, end).
tensor([ 5.,  9., 13., 17., 21., 25.])