A single
This is exactly the situation
Picture a layer that looks at a fruit's weight and its colour brightness — two numbers in, several neurons reading both. One neuron's weights might end up large on weight and near-zero on brightness, so it effectively becomes a "heaviness detector." Another might do the opposite and become a "brightness detector." A third might weight both roughly equally and end up detecting something like "overall bigness." Same two inputs, three completely different questions asked of them, all computed in one pass — that's the whole value of putting neurons in a layer rather than using them one at a time.
Without matrix notation you'd have to write out one equation per neuron by hand —
Three inputs feed a layer of two neurons. Pick an output neuron and its connections light up: its
value is that row of
Work it by hand with the numbers shown above:
A raw weighted sum on its own is just a number — it still needs an
Every entry of
Notice that squashing never mixes neurons together — neuron 1's activation depends only on neuron 1's own raw sum, never on neuron 2's. Whatever "detector" each neuron became through its weights stays that neuron's own business right through to the activation. Only the next layer, by reading every activation at once, gets to combine what the different neurons noticed.
Take a smaller layer: 2 inputs, 3 neurons. How many individual weight numbers does the layer need
to learn? It's tempting to guess 3 (one per neuron) or 2 (one per input) — but every one of the 3
neurons needs its own weight for each of the 2 inputs, so the true count is
Each row still belongs to one neuron, each column still belongs to one input — grow either number
and the matrix grows to match. Swap in the earlier example's numbers (3 inputs, 2 neurons) and you
get a
Because computers are devastatingly fast at matrix multiplication — it's exactly what GPUs are
built for. Writing a layer as
Put a number on it: a modest image-recognition layer might take 784 pixel values as input and feed 512 neurons. That's a weight matrix with 512 rows and 784 columns — 401,408 individual weights, computed for one image in a single matrix–vector multiply. A real network stacks several such layers and processes thousands of images at once; without the matrix framing, that's an unmanageable pile of individual sums.
There's no formula that hands you the perfect number — a layer's neuron count is a genuine design dial that engineers tune by hand and by experiment, the way a recipe's ingredient quantities get adjusted to taste. Too few neurons and the layer may be too simple to notice the patterns that matter (it can't even represent enough different "row detectors"); too many and the network gets slower to run, harder to train, and — as the earlier warning about network size mentioned — more prone to memorising its training examples instead of learning from them. Picking layer widths well is part science, part trial and error, and part hard-won experience.
A quick way to catch both mistakes at once: if someone tells you a layer has "10 neurons" but can't tell you how many inputs feed it, you don't yet know how big its weight matrix is — and if they hand you a weight matrix without saying which axis is rows and which is columns, you don't yet know which end the input vector plugs into. Always ask for both numbers.
GPUs — Graphics Processing Units — were built for one job: pushing millions of pixels onto a screen, sixty times a second, by doing enormous numbers of small matrix and vector calculations in parallel. Nobody designed them with neural networks in mind. But a layer of neurons is also just an enormous number of small matrix and vector calculations, done over and over — and it turns out a chip built for rendering dragons and racetracks is spectacularly good at it too. That happy coincidence, exploited from the early 2010s onward, is one of the unglamorous reasons deep learning suddenly became practical: the hardware to run it at scale was already sitting in gaming PCs.
A modern GPU can carry out many trillions of these little "multiply, then add" steps every second,
spread across thousands of tiny cores working at once. A layer's