Learn practical skills, build real-world projects, and advance your career
Updated 3 years ago
PyTorch Paanch
PyTorch is an optimized tensor library for deep learning using GPUs and CPUs.
- torch.randn()
- torch.from_numpy()
- torch.view()
- torch.device()
- torch.set_printoptions()
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
Function 1 - torch.randn()
Creates a tensor of random numbers
# Example 1 - working
x = torch.randn(2,2, dtype=torch.float)
x
tensor([[-0.0502, -0.2199],
[ 0.2780, 0.1898]])