AI Engineering 101: The Mathematical Language — Vectors and Matrices
AI Engineering 101: The Mathematical Language — Vectors and Matrices
Meta Description Learn how vectors and matrices form the mathematical foundation of modern AI and how neural networks use linear algebra for data transformations.
Introduction
Artificial intelligence may seem abstract, but at its core, it’s built on a precise mathematical language: linear algebra. In this article, you’ll discover how vectors and matrices represent data and power the computations inside machine learning models — from simple operations to deep neural networks.
Why Linear Algebra Matters in AI
In machine learning, we convert real-world information into numbers. These numbers are organized into vectors and matrices, which models use to learn patterns and make predictions.
- Vectors represent data points or features.
- Matrices represent collections of vectors or transformations.
This structure allows machines to perform complex operations efficiently.
What is a Vector?
A vector is essentially a list of numbers.
text[2, 4, 6]
This vector might represent features like:
- age
- height
- test score
Vectors are used extensively in:
- input features
- document embeddings
- weights in models
Introduction to Matrices
A matrix is a 2-dimensional array of numbers:
text⎡1 2 3⎤ ⎣4 5 6⎦
Matrices can represent:
- multiple data points (rows)
- weight connections in neural networks
- transformations
Matrix Multiplication
Matrix multiplication is the heart of neural networks.
textIf A is a matrix and x is a vector, then: y = A × x
This operation transforms input into another space — the fundamental mechanism behind how AI computes.
Role of Matrices in Neural Networks
Neural networks use matrix multiplication in every layer.
We have:
- Input vector x
- Weight matrix W
- Output vector y
texty = W × x
This computes the activation of each neuron and drives the learning process.
Hands-On: Matrix Operations in Python
pythonimport numpy as np # Vector representing a data point x = np.array([2, 3]) # Weight matrix W = np.array([ [1, 4], [2, 5], [3, 6] ]) # Matrix × Vector using dot() y = np.dot(W, x) print("Using dot():", y) # Matrix × Vector using matmul() y2 = np.matmul(W, x) print("Using matmul():", y2) # Batch Processing: Matrix × Matrix X = np.array([ [1, 2], [3, 4] ]) W2 = np.array([ [2, 0], [1, 3] ]) Y = np.matmul(X, W2) print(Y)
The Output
textUsing dot(): [14 19 24] Using matmul(): [14 19 24] [[ 4 6] [10 12]]
Wrap-Up
Vectors and matrices give structure to machine learning. Understanding them helps you interpret how data moves through models — from raw numbers to intelligent outputs.
textInput Vector → Matrix Multiply → Add Bias → Activation → Repeat
Once you understand this, the mathematics behind modern AI becomes clear and intuitive.
Hands-On: Linear Algebra in Action (House Price Prediction)
To understand how vectors and matrices work in real AI tasks, let’s look at a price prediction example using NumPy.
We represent the features of a house as a vector, define weights, compute predictions using the dot product, and extend it to batch predictions with matrix multiplication.
pythonimport numpy as np # Single house features house_features = np.array([2500, 3]) # Model weights weights = np.array([200, 50000]) # Prediction using dot product predicted_price = np.dot(house_features, weights) print(f"Predicted Price: ${predicted_price}")
Output:
textPredicted Price: $650000
Batch Prediction:
pythonhouse_batch = np.array([ [2500, 3], [1800, 2], [3200, 4] ]) batch_predictions = np.matmul(house_batch, weights) print(f"Batch Predictions: {batch_predictions}")
Output:
textBatch Predictions: [650000 460000 840000]
Share this article
Related Articles
Deep Learning 101: From Foundations to Real-World Applications
A deep dive into Deep learning for AI engineers.
Machine Learning Models 101: From Theory to Practice
A deep dive into Machine Learning Models for AI engineers.
Cosine Search and Cosine Distance in RAG: The Foundation of Semantic Retrieval
A deep dive into Cosine Search and Cosine Distance in RAG for AI engineers.

