0PricingLogin
Learn AI with Python · Lesson

PyTorch Tensors and Autograd

torch.Tensor, requires_grad, backward(), gradient computation, tensor operations.

What is PyTorch?

PyTorch is a deep learning framework built around tensors, multi-dimensional arrays with GPU acceleration and automatic differentiation. The two pillars you must master first are tensors and autograd.

pip install torch

import torch

Creating Tensors

A tensor is like a NumPy array but can live on a GPU and track gradients. Create one with torch.tensor. Tensors have a shape and a dtype.

x = torch.tensor([1.0, 2.0, 3.0])
print(x.shape)   # torch.Size([3])
print(x.dtype)   # torch.float32

All lessons in this course

  1. PyTorch Tensors and Autograd
  2. Custom Datasets and DataLoaders
  3. Building and Training CNNs in PyTorch
  4. Object Detection with YOLOv8
← Back to Learn AI with Python