Skip to content
ContentLora

    Tip: press / anywhere to search.

    Explainer

    Linear algebra for machine learning: vectors, matrices, dot products

    Linear algebra is the maths of arrays of numbers, and a standard deep learning textbook calls a good grasp of it essential for understanding most machine learning, especially deep learning.[1] Models store their inputs and their learned knowledge as vectors (ordered lists of numbers), matrices (grids) and tensors (grids with more axes).[2][3] Most of the work inside a model is matrix multiplication, which is built from dot products.[4][5]

    Editor reviewedUpdated Explainer14 claims · 71% primaryMachine learning foundations, Artificial intelligence
    Reading level: 2 passages differ; the rest is the same for everyone.

    This is the first step in our machine learning foundations series. Read it alongside probability for machine learning, then how machine learning works and how gradient descent works.

    A trained machine learning model is, at bottom, a large collection of learned numbers, its weights and biases.[6] Linear algebra is the maths of organising and combining arrays of such numbers.[3] The deep learning textbook by Goodfellow, Bengio and Courville calls a good understanding of it essential for understanding and working with many machine learning algorithms, especially deep learning.[1] This page explains the handful of ideas that matter most.

    Vectors: lists of numbers

    A vector is an ordered list of numbers.[2] You can picture it as an arrow or a point: a list of two numbers marks a spot on a flat map, and each extra number adds another direction.[7] Machine learning vectors are usually much longer than two or three numbers. They often have a huge number of dimensions.[2]

    When a model turns a word, an image or a product into a vector, it is giving that thing a position in a space with many directions.[7] A vector learned this way is called an embedding.[8]

    A vector is an array of numbers arranged in order. In machine learning its entries are usually floating-point numbers, and its length is called its dimension.[2] Geometrically, a vector identifies a point in space, with each element giving the coordinate along a different axis.[7] Embedding vectors are arrays of floating-point numbers, often trained in an embedding layer, that represent inputs such as words or species.[8] See how embeddings work.

    Matrices and tensors: grids of numbers

    A matrix is a two-dimensional grid of numbers, so each entry is found with two indices, a row and a column.[3] A tensor generalises the idea: an array of numbers on a regular grid with any number of axes.[3] Google’s machine learning glossary, describing tensors in TensorFlow, calls them N-dimensional data structures, most commonly scalars, vectors or matrices.[3] How neural networks work explains how models use these arrays in layers.

    The dot product: one number from two lists

    The dot product takes two lists of the same length, multiplies the matching numbers and adds up the results. The answer is a single number.[5] For the lists (1, 2, 3) and (4, 5, 6), it is 1×4 + 2×5 + 3×6 = 32.

    Embedding systems often compare vectors with a related score, cosine similarity, which looks only at direction and runs from -1 (opposite) to 1 (most similar).[9]

    The dot product (inner product) of two vectors of the same dimension is the scalar sum of the products of their entries, written xᵀy.[5] Cosine similarity normalises it by the vectors’ lengths, so it depends on direction only and ranges from -1 to 1.[9] In a Transformer, attention weights come from how well a query matches each key, and the output is a weighted sum of value vectors.[10] See how transformers work.

    Matrix multiplication: many dot products at once

    You can multiply two matrices only when the first has as many columns as the second has rows. An m×n matrix times an n×p matrix gives an m×p matrix.[4] Each entry of the result is the dot product of one row of the first matrix with one column of the second. Matrix multiplication is not just multiplying matching entries.[4] So once you understand the dot product, you understand what each number in a matrix product means.

    Size, direction and the gradient

    A few more ideas appear constantly in machine learning papers:

    • Norms. A norm measures the size of a vector. Intuitively it is the distance from the origin to the point. The everyday Euclidean (L2) norm is used so often that it is usually written without a label.[11] L2 regularisation, a common guard against overfitting, penalises large weights and pulls them toward zero.[12] See overfitting and generalization.
    • Eigenvectors. An eigenvector of a square matrix is a nonzero vector that the matrix only stretches or shrinks. The stretch factor is its eigenvalue.[13] Breaking a matrix into eigenvectors and eigenvalues reveals many useful facts about it.[13]
    • The gradient. The gradient is the vector of partial derivatives of a function with respect to each of its inputs, and it points in the direction of steepest ascent.[14] Training a model means stepping the opposite way, downhill on the error. That is the subject of how gradient descent works.

    This page covers the ideas needed to follow the rest of the series, not a full linear algebra course. University courses and textbook chapters go much further, into matrix inverses, determinants and decompositions.

    Next in the crash course

    Questions readers ask

    How much linear algebra do I need for machine learning?

    The deep learning textbook by Goodfellow, Bengio and Courville calls a good understanding of linear algebra essential for working with many machine learning algorithms, especially deep learning. Its own chapter covers vectors, matrices, tensors, matrix multiplication, norms and eigendecomposition.[1][3][11][13]

    What is a vector in machine learning?

    An ordered list of numbers. In machine learning the numbers are usually floating-point values, the count of numbers is the vector's dimension, and vectors often have a huge number of dimensions.[2]

    What is a dot product?

    For two vectors of the same length, multiply the matching entries and add up the results. The answer is a single number. Each entry of a matrix product is one such dot product.[5][4]

    What is a tensor?

    An array of numbers arranged on a grid with any number of axes. Scalars, vectors and matrices are the most common cases.[3]

    Sources

    · 14 claims from 6 publishers

    Each numbered claim is a statement we checked against the sources listed with it. Tap a number in the text to see its sources in place.

    1. [1]

      The deep learning textbook by Goodfellow, Bengio and Courville says a good understanding of linear algebra is essential for understanding and working with many machine learning algorithms, especially deep learning algorithms. confirmedas of 2026-11-22

    2. [2]

      A vector is an ordered array of numbers; in machine learning, vectors usually hold floating-point numbers, the number of elements is the vector's length or dimension, and machine learning vectors often have a huge number of dimensions. confirmedas of 2026-11-22

    3. [3]

      A matrix is a two-dimensional array of numbers whose elements are identified by two indices, and an array of numbers on a regular grid with a variable number of axes is called a tensor; Google's machine learning glossary, describing TensorFlow, calls tensors N-dimensional data structures, most commonly scalars, vectors or matrices. confirmedas of 2026-11-22

    4. [4]

      Two matrices can be multiplied only when the first has as many columns as the second has rows; an m by n matrix times an n by p matrix gives an m by p matrix, each entry of which is the dot product of a row of the first matrix and a column of the second, and the result is not simply the products of the individual elements. confirmedas of 2026-11-22

    5. [5]

      The dot product (or inner product) of two vectors of the same size is a single real number, the sum of the products of their corresponding entries. confirmedas of 2026-11-22

    6. [6]

      In supervised learning, a model is a complex collection of numbers that defines the mathematical relationship between input features and output labels; these learned numbers, the weights and biases, are called parameters. reportedas of 2026-11-07

    7. [7]

      The textbook says vectors can be thought of as identifying points in space, with each element giving the coordinate along a different axis. confirmedas of 2026-11-22

    8. [8]

      Google's glossary describes an embedding vector as an array of floating-point numbers, often trained in an embedding layer, that describes an input; for example, one vector per tree species. reportedas of 2026-11-22

    9. [9]

      Google's Gemini documentation calls cosine similarity a good measure for embeddings because it looks at direction rather than magnitude, with values from -1 (opposite) to 1 (most similar). confirmedas of 2026-11-14

      • Embeddings (Gemini API) · Google AI for Developers · Primary source · Semantic similarity (retrieved 2026-11-14)
    10. [10]

      The paper describes an attention function as mapping a query and a set of key-value pairs to an output; the output is a weighted sum of the values, with each weight computed from how well the query matches the corresponding key; in a self-attention layer, the queries, keys and values all come from the same place. confirmedas of 2017-06-12

    11. [11]

      Machine learning usually measures the size of a vector with a function called a norm, which intuitively gives the distance from the origin to the point; the L2 or Euclidean norm is used so often that it is frequently written without a subscript. confirmedas of 2026-11-22

    12. [12]

      L2 regularisation penalises large weights, encouraging them toward zero without pushing them all the way to zero, which usually lowers a model's overall complexity. reportedas of 2026-11-22

    13. [13]

      An eigenvector of a square matrix is a nonzero vector that the matrix only rescales, multiplying it by a number called the eigenvalue; the eigendecomposition of a matrix reveals many useful facts about it. confirmedas of 2026-11-22

    14. [14]

      Google's machine learning glossary defines the gradient as the vector of partial derivatives with respect to all the independent variables, and says it points in the direction of steepest ascent. reportedas of 2026-11-22

    Revision history (1)
    1. Page created.

    Created Nov 22, 2026. Last reviewed by an editor on Nov 22, 2026. Next scheduled review: Jun 7, 2027.

    Cite this page

    "Linear algebra for machine learning: vectors, matrices, dot products." ContentLora, updated Nov 22, 2026. https://contentlora.com/explain/linear-algebra-for-machine-learning

    Spotted an error? Suggest a correction or emailcorrections@contentlora.com.