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 , as in , 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 matrix by an one needs the inner sizes to agree and gives . When a formula confuses you, write the shape under each term; a mismatch usually shows where you misread it.
Example
The shared 4 disappears; the outer sizes remain.
Where the course uses it
Related terms
- Tensor — numbers on any number of axesAn array of numbers with any number of axes. In code every array is called a tensor: a scalar has 0 axes, a vector 1, a matrix 2. In prose the word usually means 3 or more.
- Matrix — a table of numbersA rectangular table of numbers, with two axes: rows and columns. An m×n matrix has m rows and n columns. Written as a capital letter, such as W.
- Matrix multiplicationTwo matrices written side by side, like AB, are multiplied. Each entry of the result is a row of A dotted with a column of B. An (m×n) times an (n×p) gives an (m×p).
- ℝ^d — all vectors of length dRead "R d" or "R to the d". It is the set of all lists of d real numbers, so "x ∈ ℝ^d" says x is a vector of d numbers.