VLA · Prerequisite · Mathematics for Deep Learning
M1.1 — Linear Algebra: Vectors, Matrices and Matrix Multiplication
How data is represented as arrays, and how a neural network layer transforms it.
Every model in the VLA roadmap, from a vision encoder to a transformer to an action head, is built from one operation repeated many times: multiplying arrays of numbers. This lesson gives you that operation and the habit of checking its shapes. No robotics knowledge is needed.
Learning objectives
After this lesson, you should be able to:
- Describe a vector and a matrix, and read their shapes.
- Compute a dot product.
- Multiply a matrix by a vector, and a matrix by a matrix, by hand on small examples.
- Say whether two shapes can be multiplied, and what shape the result has.
- Explain a neural network layer as a matrix multiplication plus an offset.
- Explain why the order of matrix multiplication matters.
- Data as a vector (a list of numbers)
- A layer’s weights as a matrix
- Matrix multiplication transforms the vector
- A nonlinearity, then the next layer
- The output: a new vector
The one-sentence idea
A neural network layer takes a vector of numbers, multiplies it by a matrix of learned numbers, and returns a new vector.
Learn to read shapes, and you can read most model code.
Why this matters for VLA models
A Vision-Language-Action model works with very different kinds of information. Linear algebra gives all of it the same form:
- A camera image is an array of pixel values, and an image encoder turns it into vectors.
- A word or instruction becomes a list of vectors, one per token.
- The robot’s state, such as its joint angles, is a vector.
- The action the model outputs, such as the next joint targets or gripper command, is a vector.
Once everything is a vector or a matrix, the model can transform it with the same operation everywhere. The attention mechanism you will meet in module 3 is also built from matrix multiplications and dot products.
Vectors
A vector is an ordered list of numbers. The number of entries is its dimension, and its shape is written (n,) for n entries. The order matters: the first number always means the same thing.
- A robot arm’s joint angles (radians)
[0.10, -0.50, 1.20]: three joints, so a 3-dimensional vector.- One RGB pixel
[255, 0, 0]: red, green and blue values, so a pure red pixel.- A word embedding
- A list of, for example, a few hundred numbers that a model has learned to represent a word. Module 3 covers how.
You can add two vectors of the same size entry by entry, and scale a vector by multiplying every entry by one number:
The dot product
The dot product of two vectors of the same size multiplies matching entries and adds the results into a single number:
The dot product measures how much two vectors point the same way. Two vectors that line up give a large positive value, and two that are perpendicular give zero. This is why models use it as a similarity score: comparing an image embedding with a text embedding, or a query with a key inside attention, comes down to dot products.
Matrix multiplication, which comes next, is just many dot products arranged in a table.
Matrices
A matrix is a table of numbers with rows and columns. Its shape is written (rows, columns), so a matrix with 2 rows and 3 columns is (2, 3), often said “2 by 3”.
Matrices appear in two main roles:
- As data. A grayscale image is a matrix of brightness values. A batch of vectors, one per row, is a matrix too.
- As a transformation. A matrix can act on a vector and produce a new one. The weights of a neural network layer are exactly such a matrix.
Matrix times vector
To multiply a matrix by a vector, take the dot product of each row of the matrix with the vector. Each row produces one entry of the result.
The input vector has 3 entries and the matrix has 3 columns, so they fit. The matrix has 2 rows, so the result has 2 entries. A (2, 3) matrix has turned a 3-dimensional vector into a 2-dimensional one. In general, a matrix with m rows and n columns takes an n-dimensional vector to an m-dimensional one.
The matrix is a function: vector in, vector out.
Matrix times matrix
Multiplying two matrices repeats this idea: each entry of the result is the dot product of a row of the first matrix with a column of the second.
Now reverse the order:
A × B and B × A are different. Here B swaps columns when it is on the right, and swaps rows when it is on the left. Matrix multiplication is not commutative: the order is part of the meaning. (It is associative, so (A×B)×C = A×(B×C), which is why a chain of layers can be grouped in any way.)
Checking shapes
You can check a multiplication without calculating anything. The inner dimensions must match, and the outer dimensions give the result shape:
| Multiplication | Valid? | Result shape |
|---|---|---|
(4, 3) × (3, 5) | Yes, inner sizes are both 3 | (4, 5) |
(2, 3) × (3,) | Yes | (2,) |
(4, 3) × (4, 5) | No, 3 does not equal 4 | Error |
(3, 5) × (4, 3) | No, 5 does not equal 4 | Error |
In practice, “shapes cannot be multiplied” is one of the most common errors in deep learning code, and reading the shapes is how you find the cause.
The same operation in NumPy is written with the @ operator. This is the example from above, and you can run it:
import numpy as np
W = np.array([[1, 2, 0],
[0, 1, 3]]) # shape (2, 3)
x = np.array([2, 1, 1]) # shape (3,)
print(W @ x, (W @ x).shape)Output:
[4 4] (2,)
A neural network layer
A basic linear layer applies a weight matrix W to its input vector x and then adds a vector of offsets b called the bias:
If x has 512 entries and the layer should produce 256 outputs, then W has shape (256, 512) and b has 256 entries. The entries of W and b are the learned parameters: training adjusts them, which later modules cover. The layer itself is nothing more than the multiplication you just did.
Models normally process many examples at once, called a batch. The batch is stored as a matrix with one example per row, and one multiplication handles all of them. One practical note: some libraries, including PyTorch’s nn.Linear, store the weights as (out, in) and compute x Wᵀ + b on row-vector batches. It is the same maths with the arrays arranged differently, which is one more reason to read shapes carefully.
Why layers need a nonlinearity
Suppose you stack two linear layers with no extra step between them:
Because matrix multiplication is associative, the two layers collapse into a single matrix W₂W₁. Stacking more would not make the model any more expressive. Real networks therefore apply a nonlinear function after each linear layer, such as the common ReLU, which sets negative values to zero. That is what lets a deep network represent complicated patterns. Module 2 returns to this when it covers neural networks.
A robotics example: rotating a point
Matrices are also how robots describe geometry. In two dimensions, rotating a point by 90° counter-clockwise about the origin is a matrix multiplication:
The point (1, 0) on the x-axis moves to (0, 1) on the y-axis. Changing coordinate frames and moving a robot’s hand are built from matrices like this one, and module 5 covers them properly. For now, the useful observation is that the same tool describes both a neural network layer and a geometric transformation.
Common misconceptions
Misconception 1 “Matrix multiplication multiplies matching entries.”
Correction Multiplying matching entries is a different operation, called element-wise multiplication. Matrix multiplication takes dot products of rows with columns.
Misconception 2 “The order doesn’t matter, as with ordinary numbers.”
Correction In general A×B and B×A differ, and one of them may not even be defined. The shapes are different.
Misconception 3 “A matrix is only a picture or a table of data.”
Correction Matrices store data, but they are also functions that transform vectors. A layer’s weights are a matrix used as a function.
Misconception 4 “More linear layers always make a more powerful model.”
Correction Without a nonlinearity between them, any number of linear layers is equivalent to one matrix.
Engineering takeaways
- A vector is an ordered list of numbers, and a matrix is a table of numbers. Both have a shape.
- The dot product multiplies matching entries and sums them, and works as a similarity score.
- Matrix times vector takes the dot product of each row with the vector.
- Matrix times matrix needs matching inner dimensions, and the result takes the outer ones.
- The order of multiplication matters.
- A linear layer is
y = Wx + b, withWandblearned. - Nonlinearities between layers stop a stack of layers collapsing into one.
- When code fails with a shape error, write the shapes down and check the inner dimensions.
Read the shapes first: they tell you what a multiplication can do before you calculate a single number.
Knowledge check
Try each question first, then reveal the explanation.
Question 1
A matrix A has shape (4, 3) and a matrix B has shape (3, 5). Can you compute A × B? What is the result shape? What about B × A?
Explanation
A × B is valid and has shape (4, 5). The inner dimensions are both 3. B × A is not valid: its inner dimensions are 5 and 4, which do not match.
Question 2
A layer maps a 100-dimensional input to a 20-dimensional output with y = Wx + b. What are the shapes of W and b?
Explanation
W is (20, 100) and b has 20 entries. A (20, 100) matrix takes a 100-dimensional vector to a 20-dimensional one, and the bias is added to the 20 outputs.
Question 3
Why is a network made of ten linear layers with no nonlinearity no more expressive than a single linear layer?
Explanation
Because the ten matrices multiply together into one matrix. Matrix multiplication is associative, so W₁₀ ⋯ W₂ W₁ is a single matrix, and the network can only do what that one matrix does. A nonlinear step between layers prevents this.
What’s next
You can now read vectors, matrices and shapes. Next is how a network learns the numbers inside its matrices.