Course map
Stage 1: Foundations
Stage 2: Machine Learning
Stage 3: Deep Learning
Stage 4: LLMs & Generative AI
Stage 5: Production & Specialization

Part 10 / Topic 1 of 7

Tensors

A tensor is NumPy's array with two superpowers: it can live on a GPU, and it can carry gradients.

t = torch.tensor([[1., 2.], [3., 4.]])
t.shape, t.dtype, t.device     # torch.Size([2, 2]) torch.float32 cpu
t.reshape(4)                   # [1., 2., 3., 4.]
t.T                            # transpose, like NumPy

Two habits from day one: float32 is the default and what layers expect (x.float() converts — a float64 input into a float32 layer is this stage's most common crash); and .to(device) moves tensors between CPU and GPU — model and data must be on the same one.

Done here? The practice set for Part 10 — 4 exercises with solutions — is on the part page.

Search the guide