(2, 3, 4)(2,\, 3,\, 4)

Shape and axes

A tensor's shape lists the size of each axis, in order. (2, 3, 4) has three axes of sizes 2, 3 and 4. Checking shapes is the quickest way to follow a formula.

An axis is one direction you can step along: along a vector, down the rows of a matrix, across its columns. The shape records how many steps each axis has. The course writes a shape in the exponent of R\mathbb{R}, as in R2×3×4\mathbb{R}^{2 \times 3 \times 4}, and PyTorch prints it as torch.Size([2, 3, 4]).

Most operations have a shape rule. Adding two tensors needs the same shape and keeps it. Multiplying an m×nm \times n matrix by an n×pn \times p one needs the inner sizes to agree and gives m×pm \times p. When a formula confuses you, write the shape under each term; a mismatch usually shows where you misread it.

Example

X⏟3×4  W⏟4×2=Y⏟3×2\underbrace{X}_{3 \times 4}\;\underbrace{W}_{4 \times 2} = \underbrace{Y}_{3 \times 2}

The shared 4 disappears; the outer sizes remain.

Where the course uses it

Related terms