Linear Algebra - Vectors, Matrices, and Dot Products
2.1 What Is Linear Algebra?
Linear algebra is the branch of mathematics that studies vectors, matrices, and operations involving them.
AI systems often process many numerical features simultaneously. Linear algebra provides an efficient way to represent and calculate these features.
For example, an image can be represented as a grid of pixel values, while a customer record can be represented as a collection of numerical features.
2.2 Understanding Vectors
A vector is an ordered collection of numbers.
For example:
[
\mathbf{x} = [2, 4, 6]
]
This vector contains three values. In a machine learning dataset, these values might represent normalized features such as age, income, and experience.
In Python, NumPy makes vector operations straightforward.
import numpy as np
features = np.array([2, 4, 6])
print(features)
print(features * 2)
Output:
[2 4 6]
[ 4 8 12]
The multiplication operation applies to every element of the vector.
2.3 Understanding Matrices
A matrix is a rectangular arrangement of numbers organized into rows and columns.
For example:
[
A =
\begin{bmatrix}
1 & 2 \
3 & 4
\end{bmatrix}
]
In a dataset, rows often represent individual observations and columns represent features.
import numpy as np
data = np.array([
[1, 2],
[3, 4],
[5, 6]
])
print(data.shape)
Output:
(3, 2)
The matrix contains three rows and two columns.
2.4 Understanding the Dot Product
The dot product combines corresponding elements of two vectors, multiplies each pair, and adds the results.
For vectors:
[
\mathbf{a} = [2, 3]
]
[
\mathbf{b} = [4, 5]
]
The dot product is:
[
(2 \times 4) + (3 \times 5) = 23
]
Python implementation:
import numpy as np
a = np.array([2, 3])
b = np.array([4, 5])
result = np.dot(a, b)
print(result)
Output:
23
Dot products are important in machine learning because they help calculate weighted sums. For example, a linear model may multiply each input feature by its corresponding weight and add the results.
2.5 Why Linear Algebra Matters in Modern AI
Linear algebra is used in:
- Neural network calculations.
- Image and signal processing.
- Recommendation systems.
- Text embeddings and similarity calculations.
- Large-scale machine learning computations.
Modern AI frameworks such as PyTorch and TensorFlow rely heavily on tensor operations, which extend the ideas of vectors and matrices to higher dimensions.
2.6 Practice Exercise
Create two NumPy vectors:
a = np.array([3, 5, 7])
b = np.array([2, 4, 6])
Calculate their dot product and verify the result manually.
Artificial Intelligence Tutorial
Vishalini A








