0:00Intro: MOFUSA Tech Academy
Welcome to MOFUSA Tech Academy. Beyond learning, towards mastery.
0:09Why AI needs vectors and matrices
To Brightcart, a single customer isn't a name. It's a list of numbers. Thirty days since their last order. Four orders in the last three months. An average basket of forty-seven dollars. Seven kilometres from the warehouse. And hundreds more. Now multiply that by ten thousand customers. How does a machine hold all of that, and, more importantly, compute with it, quickly? The answer is two of the most important ideas in all of AI: vectors and matrices. Every model in this course, from a straight line to a language model, is built from them.
And as you'll see, they're far friendlier than they sound.
0:55Map flight: the maths toolkit
We're on the coast of Season One, Module One: the maths toolkit. Stop two: vectors and matrices.
1:04Vectors: lists and arrows
A vector is simply an ordered list of numbers. But it also has a picture, and the picture is where the intuition lives. Dev's van drives three blocks east and four blocks north. We can write that trip as the vector three, four. And we can draw it as an arrow from where the van started to where it ended up. Vectors add the way trips add. Drive three, four, then drive one, two, and in total you've gone four, six. To add vectors, you add the matching entries. Multiplying a vector by a number scales it. Times two makes the arrow twice as long.
Times minus one flips it around. Now here's the leap. A Brightcart customer is also a vector: thirty, four, forty-seven, seven. One number per measurement. In machine learning we call each measurement a feature. With four features, every customer is a point in four-dimensional space. We can't picture four dimensions, but the maths doesn't care. Everything we do with arrows on a flat grid works exactly the same with four features, or four thousand.
2:16The dot product, explained
If you learn one operation today, make it this one: the dot product. Here's a new delivery order as a vector: seven kilometres, three items, and it's raining, which we record as one. And here's another vector, in blue: three point nine seven, zero point eight eight, seven point nine two. These are weights. How much each feature matters. To take the dot product, we multiply matching entries and add the results. Seven times three point nine seven is twenty-seven point seven nine. Three times zero point eight eight is two point six four.
One times seven point nine two is seven point nine two. Add them up: thirty-eight point three five. Then add a starting value, the bias, of four point four five. Forty-two point eight minutes. We just predicted a delivery time. These weights aren't made up, either: they're exactly what a model learned from Brightcart's real deliveries, which we'll build in Module Three. Look at what the dot product means. Each kilometre adds about four minutes. Each item adds under a minute. Rain adds almost eight. A weighted sum: every feature, multiplied by how much it matters, all added together.
This one operation is the heart of linear regression, logistic regression, support vector machines, and every single neuron in every neural network, including the ones inside language models. Billions of multiplications, every time a chatbot writes a word.
There's a geometric meaning too. The dot product of two arrows equals their lengths multiplied together, times the cosine of the angle between them. Arrows pointing the same way give a large positive number. At right angles, the dot product is zero. Pointing in opposite directions, it's negative. So the dot product also measures how much two vectors agree.
4:18Length, distance and cosine similarity
Every vector has a length, which mathematicians call its norm. For the arrow three, four, the length comes straight from Pythagoras: the square root of three squared plus four squared. Five. And if we can measure length, we can measure distance. Here are two Brightcart customers as points. To find how far apart they are, take the differences in each feature, square them, add them up and take the square root. About two point two four. Close together. Why should we care? Because in machine learning, distance means similarity.
Customers who are close in feature space tend to behave alike. That simple idea powers a whole algorithm, k nearest neighbours, which we'll build in Module Four. Sometimes we care about direction more than distance. Divide the dot product by the two lengths, and we get the cosine of the angle between the arrows. That's called cosine similarity. It's one for arrows pointing the same way and zero for arrows at right angles. In Season Two, we'll turn words into vectors. Watch: "refund" and "money back" point almost the same way, with a cosine similarity of zero point nine nine six, while "refund" and "delivery" point in quite different directions.
Similar meaning, similar direction. That one idea is how modern AI search finds the right document, even when the words don't match.
5:54Matrices: the whole dataset
A vector holds one example. To hold a whole dataset, we stack the vectors into a grid. That grid is a matrix. Here are three of Brightcart's deliveries. Each row is one order. Each column is one feature: kilometres, items, rain. By convention, the number of rows, the number of examples, is m, and the number of columns, the number of features, is n. So this is a three-by-three matrix. The full delivery table is eight by three. A real customer table might be ten thousand by three hundred. We name a single entry by its row and column.
x three-one is row three, column one: nine kilometres. One more piece of notation you'll see everywhere: the transpose, written with a small T. It flips the matrix along its diagonal, so the rows become the columns. It's how we line up shapes so they fit together, as we're about to see.
6:56Matrix times vector and the shape rule
Here's where matrices become powerful. Put the order matrix next to the weight vector and multiply. Matrix-times-vector is just a dot product for every row. Row one with the weights: two kilometres, one item, no rain. That gives eight point eight two, plus the bias, which is about thirteen point three minutes. Row two gives thirty-nine point seven. Row three gives forty-nine point nine. One multiplication, three predictions. With ten thousand rows, one multiplication gives ten thousand predictions. We write the whole thing in one short line: y-hat equals X w plus b.
The real delivery times were fourteen, thirty-eight and fifty-two minutes, so the model is close but not perfect. Those little gaps are exactly what a cost function will measure. Now, the one rule you must never forget: shapes. To multiply two matrices, the number of columns in the first has to equal the number of rows in the second. Three-by-three times three-by-one works, and gives three-by-one. In general, m-by-n times n-by-k gives m-by-k. The inner numbers must match, and the outer numbers give the shape of the answer.
Get a shape error in your code, and this rule is almost always the reason. Multiplying two full matrices follows the same idea: every cell in the result is the dot product of one row and one column. And here's why AI runs on graphics cards: all of those dot products are independent, so a GPU can compute thousands of them at the same time.
8:38How a matrix bends space
There's one more way to see a matrix, and it's the one that will make neural networks click in Season Two. A matrix is a machine that transforms space. Watch this grid. Multiply every point by this matrix and the whole space stretches sideways. This one rotates it by ninety degrees. This one shears it, so everything leans. There's a neat trick for reading any two-by-two matrix: its columns tell you where the two axis arrows land. The first column is where the x-arrow ends up, and the second is where the y-arrow ends up.
Everything else follows along. Why does this matter? Because a neural network is, at heart, a stack of these transformations, with a little bend added between each one. Each layer warps the data until things that were tangled become easy to separate. Keep this picture in your mind. We'll come back to it.
9:37Try it yourself: a dot product and a shape check
Time to try it yourself. A new delivery: four kilometres, two items, and no rain. Using the weights from earlier, rounded, what's the predicted delivery time? Pause and work it out. Four times three point nine seven is fifteen point eight eight. Two times zero point eight eight is one point seven six. No rain, so zero. That's seventeen point six four, plus the bias of four point four five: about twenty-two minutes. Now a shape check. A table of ten thousand customers with three hundred features, multiplied by a weight vector of length three hundred.
What shape comes out? Ten thousand by one: one prediction per customer. And a five-by-three matrix times a four-by-two matrix? Not allowed. The inner numbers, three and four, don't match. If you can do these two checks in your head, you can read the maths of almost any model.
10:43Everything becomes a vector
Here's what makes vectors so powerful: almost anything can become one. A small black-and-white image of a handwritten digit, eight pixels by eight, is just sixty-four brightness values. Unroll the grid row by row and it's a vector of sixty-four numbers. A review can become a vector of word counts. A product can become a vector of its price, weight, rating and category. And once something is a vector, all the tools from today work on it: distances, dot products, matrix multiplication. One more useful trick: normalising.
Divide a vector by its own length, and you get a vector pointing the same way with length exactly one. Three, four has length five, so it becomes zero point six, zero point eight. And here's a neat connection: the cosine similarity from earlier is simply the dot product of two normalised vectors.
11:42Why vectorised code is fast
There's a practical reason AI engineers think in vectors and matrices: speed. To predict delivery times for ten thousand orders with three hundred features each, you could loop through every order and every feature, three million tiny multiply-and-add steps, one at a time. Or you can write it as a single matrix multiplication, and hand it to software and hardware built to do exactly that, in one fast operation. In code, that whole computation is often a single short line: predictions equal X times w, plus b. Thinking in whole vectors and matrices, instead of individual numbers, is called vectorised thinking.
It's how neural networks in Season Two process thousands of images or words at once.
12:31Identity and inverse matrices
Two special matrices complete our toolkit. The identity matrix has ones on its diagonal and zeros everywhere else. Multiplying by it changes nothing: the grid stays exactly where it is. It's the matrix version of multiplying by one. The inverse of a matrix undoes it. If a matrix stretches space sideways by a factor of two, its inverse squeezes it back by a half, and doing one after the other returns everything to where it started: the identity. But not every matrix has an inverse. A matrix that squashes the whole plane flat onto a line destroys information, because many different points land in the same place, and there's no way to undo that.
Such matrices have a determinant of zero. Keep that in mind: in episode nine, the inverse appears in the exact formula for linear regression, and a missing inverse turns out to mean that some features are redundant: one is an exact copy, or an exact combination, of others.
13:36Myth vs Fact: do you need linear algebra for AI?
Myth: linear algebra is only for mathematicians, and you can skip it to do AI. Fact: you'll see it everywhere. Linear regression is a matrix times a vector. A neural network layer is a matrix times a vector, passed through a bend we'll meet later. And the attention mechanism inside every modern language model is built from matrix products and a transpose. The good news is that you've just learned the parts that matter most: vectors, dot products, distances, matrix multiplication and the shape rule. That's genuinely most of the linear algebra you need for this entire course.
14:16Recap
Let's recap. A vector is an ordered list of numbers. We can picture it as an arrow, and in machine learning it holds one example. The dot product multiplies matching entries and adds them up: a weighted sum, and the core of nearly every model. Length, distance and cosine similarity tell us how alike two examples are. A matrix holds a whole dataset, and multiplying it by a weight vector makes a prediction for every row at once, as long as the shapes line up. If you remember one sentence, make it this one: every prediction starts as a dot product.
14:54Next: derivatives and gradients
Mission complete. Every customer becomes a vector, the whole customer base becomes a matrix, and one multiplication predicts for all of them. But our predictions still have errors. To fix them, the model has to know which way to turn each of its dials, and by how much. That's what derivatives and gradients tell us, and that's next. See you at the next stop on the map.