Deep Learning Basics

Matrix multiplication is the first batch trick

5 min read

Matrix multiplication is the first place the repeated structure becomes impossible to ignore.

That is why it shows up so early in neural network lessons. The point is not to look formal. The point is to stop writing the same dot product over and over by hand. Once there is more than one neuron or more than one example, the compact version starts paying rent.

With one neuron and one input, the calculation is still straightforward:

output = input_1 * weight_1 + input_2 * weight_2 + bias

That works. But the minute the pattern repeats, matrix multiplication is the better tool.

one cell, one dot product

The clearest way to read matrix multiplication is cell by cell.

Each output value comes from one row of the left matrix and one column of the right matrix. Multiply the matching entries. Add the products. That is the whole operation.

In this example, Matrix A is 2x2 and Matrix B is 2x3, so Matrix C is 2x3.

A rows: 2
B columns: 3
C shape: 2 x 3

The shared middle dimension has to match. That is the part that often saves you from a bad shape bug before the code gets any farther. If the inner dimensions do not agree, the multiplication should not happen.

That rule looks basic, but neural network code leans on it constantly.

why the shape matters more than the arithmetic

Pick one output cell in the result.

It is just a dot product with a specific row and a specific column:

C[1, 2] = A row 1 dot B column 2

That small fact is doing a lot of work. It means each input number participates in a specific set of output cells, not all of them equally. Change one value in Matrix A and only certain rows of C move. Change one value in Matrix B and a different set of cells changes.

The interactive grid makes that dependency pattern easier to see than a page of equations does.

why neural networks keep using it

Neural networks use matrix multiplication because layers are repeated weighted sums.

If a layer has several neurons, each neuron has its own weight vector. Stack those vectors into rows and you get a matrix. If you also have several input examples, you can arrange them so the same operation processes the whole batch instead of one example at a time.

The idea stays simple:

outputs = weights * inputs

Then the network adds bias and usually applies an activation function. Matrix multiplication does not replace those steps. It just organizes the part that repeats.

That is the useful part to remember. A layer is many dot products laid out so the computer can do them efficiently.

batches are where the repetition becomes obvious

Batching is the first place matrix multiplication starts to feel natural.

Imagine running three inputs through the same layer. You could write the same weighted sum three times. After a while that becomes clutter. The model is not changing between examples. The weights are the same. The operation is the same. Only the inputs differ.

The matrix form says that directly.

The batch is not a different model. It is one model applied to several inputs.

That distinction matters because it is easy to think of a batch as a pile of examples. It is more accurate to think of it as pressure on the same parameters.

the shape checks are not decoration

Learning matrix multiplication is partly learning to debug shapes.

If A is 2x2 and B is 2x3, the multiplication works. If the shapes are swapped, it does not. The numbers may look harmless, but the shapes decide what can combine with what.

That is not pedantry. A wrong transpose in neural network code can make features look like examples or examples look like features. Sometimes the code crashes. Sometimes it runs and produces nonsense.

So before you run the example, it helps to ask:

  • how many rows should the result have?
  • how many columns should it have?
  • which dimension has to match?
  • what does each row stand for?
  • what does each column stand for?

Those are boring questions. They are also the ones that save time.

try a value change, then look at the blast radius

Use the module slowly.

Change one number in Matrix A and predict which row of Matrix C should move. Then change one number in Matrix B and see whether the affected cells match what you expected. The arithmetic matters, but the dependency pattern matters more.

That is the part worth keeping.

Matrix multiplication is not a symbol you memorize and move on from. It is the first compact way to show how a neural network reuses the same structure many times.

Rows meet columns. Dot products become cells. Cells become a layer output. Once that is visible in a 2x2 times 2x3 example, the larger versions stop looking like a wall of notation and start looking like the same trick scaled up.

Jeremy London

About Jeremy London

Engineering leader and builder in Denver. I write about AI platforms, agents, security, reliability, homelab infrastructure, and the parts of engineering work that have to survive production.