Skip to main content

Vectors and matrices: the basic language of many AI models

From data representation to linear transforms, with a worked example and a connection to model layers.

Mathematics for AIBeginner

Learning goal

Interpret vectors and matrices, perform matrix multiplication, and explain its role in a simple linear layer.

Prerequisites

  • Elementary algebra

What is a vector?

A vector is both an ordered collection of numbers and a geometric object. In machine learning, vectors often represent samples, features, or embeddings.

A two-dimensional vector
x=[21]

What does a matrix do?

A matrix applies a linear transformation to a vector. In a simple neural-network layer, a bias then shifts the result.

Linear layer
y=Wx+b

For W=[[2,1],[-1,3]] and x=[1,2], the product is [4,5].

Why does this matter for AI?

Projections, embeddings, and many operations inside neural networks are expressed through matrix multiplication. Before attention and backpropagation, this algebra should be understood both numerically and geometrically.

Exercises

  • Compute a 2×2 matrix acting on three different vectors.
  • Explain why matrix multiplication order matters.
  • What happens when W=I?

Related projects

HowAttentionWorks

Continue from linear algebra to attention.

Open source

HowTransformersWork

Continue from linear algebra to Transformers.

Open source

Related solutions

See these ideas inside a real model

The path can move from mathematical structure to implementation.