BTI Beyond The Interviews

AI & ML · 9 sections

PyTorch

Tensors, autograd, modules, and the PyTorch interview essentials.

Premium · preview 127 cards Updated 24 Oct 2026
Free to preview. The first 3 cards and the full outline are below — the rest of this sheet is part of the Backend, Databases & AI bundle.

What's inside

Preview — first 3 of 127 cards

What is a PyTorch tensor?

A multi-dimensional array (ndarray-like) that can live on CPU or GPU and supports automatic differentiation when requires_grad=True. It is the core data structure in PyTorch.

import torch
x = torch.tensor([[1., 2], [3, 4]])
print(x.shape, x.dtype, x.device)

How do you create a tensor from a list or NumPy array?

Use torch.tensor (copies data, infers dtype) or torch.from_numpy (shares memory, dtype matches). from_numpy returns a CPU tensor sharing storage with the array.

import numpy as np
a = np.array([1,2,3])
t1 = torch.tensor(a)          # copy
t2 = torch.from_numpy(a)      # shared memory
a[0] = 99; print(t2)          # t2 changes too

What are the common factory functions?

torch.zeros, ones, empty, randn, rand, arange, linspace, eye, full. empty allocates uninitialized memory (faster but unsafe to read).

torch.zeros(2,3)
torch.randn(2,3)
torch.arange(0,10,2)
torch.linspace(0,1,5)
torch.eye(3)
torch.full((2,2), 7.0)

124 more cards in this sheet

Unlock the Backend, Databases & AI bundle — ₹399

One-time payment. Unlocks this sheet and 14 other sheets in the bundle, plus a typeset PDF of each.

Unlock the bundle See all bundles

Or get all 76 sheets for ₹999 — one payment, every future sheet included.