Matrices and Linear Algebra

You've probably worked with spreadsheets before—rows and columns of data organized in a neat grid. Well, in AI the same concept is used but they're called matrices, and they are in almost everything. Whether AI is recognizing faces in photos, understanding speech, or recommending movies, it's constantly organizing and manipulating data in these mathematical tables.

Think of matrices as AI's filing system—a way to keep massive amounts of information organized so it can be processed quickly and efficiently. Every image, every sentence, every dataset gets converted into these numerical grids that AI can understand and work with.


What is a Vector?

Before we dive into matrices, let's start with something simpler: vectors. A vector is just a list of numbers that describes something specific. It's like creating a numerical profile for an object or concept.

🍕 Pizza Order Example: Imagine describing your custom pizza order with numbers:

  • Size: 30 centimetres.
  • Cheese level: 2 (normal amount).
  • Spiciness: 3 (medium heat).
  • Number of toppings: 4.

We can write this as a vector:

[30234]\begin{bmatrix} 30 & 2 & 3 & 4 \end{bmatrix}

Vectors can simply be seen as lists of numbers that describe something. This is called a 4-dimensional vector because it has 4 numbers. Each number represents a different characteristic of your pizza.

AI Applications of Vectors:

  • User preferences: Your Netflix profile might be [0.9 for action, 0.3 for romance, 0.7 for comedy, 0.1 for horror][0.9\ \text{for action},\ 0.3\ \text{for romance},\ 0.7\ \text{for comedy},\ 0.1\ \text{for horror}].
  • Word meanings: The word "king" might be represented as [0.8 for power, 0.6 for male, 0.9 for authority, 0.2 for youth][0.8\ \text{for power},\ 0.6\ \text{for male},\ 0.9\ \text{for authority},\ 0.2\ \text{for youth}].
  • Image pixels: A single pixel's color could be [255 for red, 128 for green, 64 for blue][255\ \text{for red},\ 128\ \text{for green},\ 64\ \text{for blue}].
  • Stock features: A company might be [50 for price, 0.8 for growth rate, 0.6 for stability, 0.3 for risk][50\ \text{for price},\ 0.8\ \text{for growth rate},\ 0.6\ \text{for stability},\ 0.3\ \text{for risk}].

Vectors give AI a way to convert real-world things into numbers it can mathematically manipulate and compare.


What is a Matrix?

A matrix is simply multiple vectors organized together in rows and columns—like a spreadsheet of related information. When you stack vectors together, you get a matrix that can represent complex datasets.

🍎 Fruit Recognition Example: Imagine training AI to identify different fruits. You might create a matrix where each row represents a fruit and each column represents a measurable feature:

FruitWeight (g)Redness (0-100)Sweetness
🍎 Apple1508090
🍌 Banana1202085
🍊 Orange1806075

As a matrix, this looks like:

[150809012020851806075]\begin{bmatrix} 150 & 80 & 90 \\ 120 & 20 & 85 \\ 180 & 60 & 75 \end{bmatrix}

This is a 3×3 matrix (3 rows, 3 columns). An AI system can analyze this matrix to learn patterns—like noticing that apples tend to be redder than bananas, or that oranges are typically heavier than other fruits.

Notice that we can extract vectors from this matrix in two ways:

  • Row vectors: Each row represents one fruit with all its features [150,80,90][150, 80, 90] for the apple.
  • Column vectors: Each column represents one feature across all fruits [150,120,180][150, 120, 180] for weights.

This flexibility allows AI to analyze data from different perspectives—comparing individual items or looking at how specific features vary across the entire dataset.


Matrices for Images: Turning Pictures into Numbers

There are also certain types of data that must be represented in matrices. Every digital image is actually a matrix in disguise. When you take a photo, your camera converts light into a grid of numbers that represents the brightness and color of each tiny square (pixel).

🖼 Grayscale Image Example: A simple black-and-white photo might look like this as a matrix:

[255651404512030080160]\begin{bmatrix} 255 & 65 & 140 \\ 45 & 120 & 30 \\ 0 & 80 & 160 \end{bmatrix}

Each number represents how bright that pixel is:

  • 0 is completely black.
  • 255 is completely white.
  • Numbers in between are various shades of gray.

Check out the resulting "image" below:

Growth

Color photos use three matrices stacked together—one for red, one for green, and one for blue. Your phone's camera creates these three matrices and combines them to produce the full-color image you see.

This is why AI can "see" images—it's really analyzing patterns in these numerical matrices to identify objects, faces, or scenes.


Matrices for Text: Converting Words to Numbers

AI can't directly understand words the way humans do, so it converts text into numerical matrices that it can process mathematically.

💬 Sentiment Analysis Example: Let's say we want AI to determine if these sentences are positive or negative:

  • "I love this movie".
  • "This movie is terrible".
  • "It was okay".

For building such a system, we might convert each word to a number based on its emotional content (this was actually done in early forms of text analysis!):

  • "love" → +2 (very positive).
  • "terrible" → -2 (very negative).
  • "okay" → 0 (neutral).
  • "movie", "this", "was", "it" → 0 (neutral words).

Then it can create matrices to analyze sentiment patterns across many sentences, helping it learn to recognize positive and negative language.

🤖 Language Translation Example: Translation AI uses matrices to represent relationships between words in different languages. It learns that the English word "cat" and the Spanish word "gato" should have very similar numerical representations in their respective matrices.


Data Transformation

AI doesn't just store data in matrices—it transforms them to extract useful information. This is where linear algebra becomes powerful, allowing AI to manipulate data in sophisticated ways.

🏞️ Image Processing Example: When AI (or the image editing app on your phone) enhances photos or applies filters, it's performing mathematical operations on the image matrices:

  • Blurring: Averaging nearby pixel values.
  • Edge detection: Finding where pixel values change dramatically.
  • Brightening: Adding a constant number to all pixel values.

AI can take a matrix with hundreds of features and compress it into a smaller matrix that captures the most important patterns. This is like creating a summary that keeps the essential information while removing unnecessary details. This is actually a very commonly used technique to present high-dimensional data to us humans.


Real-World Matrix Applications

Let's see how matrices work in AI systems you encounter daily:

🙈 Face Recognition Example: When your phone recognizes your face to unlock, it:

  1. Converts your face photo into matrices of pixel values.
  2. Compares these matrices to stored matrices of your face.
  3. Uses matrix operations to measure similarity.
  4. Unlocks if the similarity score is high enough.

🤖 Voice Assistant Example: When you speak to Alexa or Siri, the AI:

  1. Converts your voice into matrices representing sound frequencies.
  2. Compares these matrices to patterns of known words.
  3. Uses matrix transformations to identify the most likely words you spoke.

🔎 Search Engine Example: Google represents web pages and search queries as matrices, then uses matrix operations to calculate which pages are most relevant to your search terms.


Final Takeaways

Matrices and vectors are AI's way of organizing the world into numbers it can understand and manipulate. Every image becomes a matrix of pixel values, every sentence becomes vectors of word meanings, and every dataset becomes a structured grid of information. Linear algebra provides the mathematical tools to transform these matrices, allowing AI to find patterns, make predictions, and solve complex problems. Understanding matrices helps you see that AI isn't magic—it's sophisticated mathematical processing of well-organized numerical data.