Linear Algebra You Can See, with NumPy
·
Course overview
1
Writing the world as lists of numbers: vectors and NumPy arrays
2
Vector = arrow = list of numbers: addition and scaling
3
Length, angle and the dot product
4
Linear combinations and span
5
A matrix is a rule for moving space
6
Matrix multiplication = one transformation after another
7
Determinants and inverses
8
Solving Ax = b
9
Column space, null space and rank
10
Changing basis
11
Eigenvalues and eigenvectors
12
Diagonalization and matrix powers
13
Orthogonality, projection and least squares
14
SVD: rotate, stretch, rotate
15
PCA, and the next step
Time 0:00–0:50
Open a linear algebra book and the first chapter throws "vector spaces" and "modules over a field" at you. If that is where you closed the book, this course starts right there.
The truth is that developers already handle the things linear algebra is about, every day. A mouse position on screen (320, 180), a color (255, 128, 0), the counts in a shopping cart, the list of 768 numbers a search engine turns a sentence into: all of these are numbers bundled together in a fixed order. Linear algebra is the set of rules for adding, stretching, rotating and comparing such bundles.
This lesson has almost no calculation. You will learn to see a bundle of numbers as a picture, to read the book's notation, and to build the same thing as a NumPy array.
A bundle of numbers in a fixed order is called a vector. Each number in the bundle is a component, and the number of components is the vector's dimension.
| What it records | The numbers | Dimension |
|---|---|---|
| A point on screen | (320, 180) | 2 |
| A color (red, green, blue) | (255, 128, 0) | 3 |
| A shopping cart (apples, milk, bread) | (3, 1, 2) | 3 |
| A 28 × 28 grayscale photo | one brightness per pixel | 784 |
The most important word here is order. The cart (3, 1, 2) only means "3 apples, 1 milk, 2 breads" because we agreed on what each slot holds. The same numbers as (1, 3, 2) are a completely different cart. When you work with vectors, always settle first on what each position means.
No need to be scared of 784 dimensions. You cannot draw a 784-dimensional vector, but it is just a list of 784 numbers in a fixed order. This course builds intuition in two dimensions, where everything can be drawn, and then applies the very same rules in any number of dimensions with NumPy.
A two-dimensional vector can be drawn as a single point on the plane. The first number says how many steps right from the origin (x), the second how many steps up (y). Negative numbers go the other way, left or down.
Drag the black point P in the lab below. The teal bar is x and the crimson bar is y. Also try dragging it down and to the left, and watch both numbers turn negative.
Textbooks write the numbers stacked vertically
x: how many steps right
y: how many steps up
Written in a row: (3, 2)
Check it with NumPy
Each time you settle on a value in the lab, the server runs NumPy on the same numbers.
>>> import numpy as np
>>> p = np.array([3, 2])
>>> p
array([3, 2])
>>> p.shape
(2,)
>>> p.dtype
dtype('int64')
>>> p[0]
np.int64(3)
>>> p[1]
np.int64(2)On the right of the lab, the same point appears with its two numbers stacked vertically. That is the standard way books write a vector. It means exactly the same as writing (3, 2) in a row. Why books stack them becomes clear in Lesson 5, when we multiply by matrices.
Drag the point back and forth between (3, 2) and (2, 3) and you can see with your own eyes that the same two numbers in a different order are a completely different place.
A big reason linear algebra books feel hard is the notation. Symbols are just shorthand for longer words, so learning to read them out loud first makes them far less strange.
| What the book writes | Read it as | Meaning | In Python |
|---|---|---|---|
| (bold) | vector v | the name given to one bundle of numbers | v = np.array([3, 2]) |
| (arrow) | vector v | same meaning, mostly used in handwriting | same as above |
| v one, v two | the first and second components of v | v[0], v[1] | |
| R, the real numbers | every number, decimals included | float | |
| R two | all vectors of two real numbers = the plane | an array with shape (2,) | |
| v is in R three | v is a vector of three real numbers | v.shape == (3,) |
A column vector is written like this.
One thing to watch out for: books count from 1, Python counts from 0. The book's is Python's p[0]. Mistakes from this difference are very common, so keep it in mind from the start.
You can bundle numbers in a Python list too, but for linear algebra we use NumPy. A NumPy array only holds numbers of one kind, and in exchange it computes fast and supports the vector operations you will meet from the next lesson on.
Installing it takes one line. Every output in this course is from NumPy 2.x.
pip install numpy # or: uv add numpyBy convention NumPy is imported under the short name np. You make an array by passing a list to np.array.
>>> import numpy as np
>>> p = np.array([3, 2])
>>> p
array([3, 2])The first two things to check about any array are shape and dtype. shape tells you "how many numbers, in what layout", and dtype tells you "what kind of numbers".
>>> p.shape
(2,)
>>> p.dtype
dtype('int64')
>>> p.ndim
1
>>> len(p)
2(2,) means "one row of 2 numbers". The comma is there because Python writes a one-element tuple as (2,). ndim is the number of axes. A vector, with its numbers in a single row, has one axis, so it is 1.
Put in only integers and you get int64; mix in a single decimal and the whole array becomes float64. That is what happened in the lab when you moved the point to 3.5.
>>> q = np.array([3.5, 2])
>>> q
array([3.5, 2. ])
>>> q.dtype
dtype('float64')2. is short for 2.0. Every number in an array must be of the same kind, so the integer 2 became the real number 2.0.
Components come out with square brackets. Counting starts at 0, and negative indices count from the end.
>>> color = np.array([255, 128, 0])
>>> color[0]
np.int64(255)
>>> color[-1]
np.int64(0)
>>> color[0:2]
array([255, 128])np.int64(255) means "the 64-bit NumPy integer 255". In calculations you can usually treat it exactly like the plain integer 255. A range like color[0:2] gives a new array from index 0 up to but not including index 2, that is, two components.
784 dimensions are made the same way. You cannot draw it, but shape still tells you what it is.
>>> photo = np.zeros(784)
>>> photo.shape
(784,)
>>> photo[:5]
array([0., 0., 0., 0., 0.])Passing the numbers without wrapping them in a list. The first argument of np.array is one bundle of numbers. Pass the numbers separately and NumPy tries to read the second one as a "kind of number" (dtype), and fails.
>>> np.array(3, 2)
Traceback (most recent call last):
...
TypeError: Cannot interpret '2' as a data typeCounting from 1. If you reach for the book's $p_2$ with p[2], you run off the end of a vector that only has two components.
>>> p = np.array([3, 2])
>>> p[2]
Traceback (most recent call last):
...
IndexError: index 2 is out of bounds for axis 0 with size 2a. Predict a.shape and a.dtype first, then check.(255, 128, 0)? Using the book's notation, which set does it belong to?v = np.array([4, 7, 1, 9]), take out the last component and the first three components.>>> a = np.array([-2, 1.5])
>>> a.shape
(2,)
>>> a.dtype
dtype('float64')
>>> v = np.array([4, 7, 1, 9])
>>> v[-1]
np.int64(9)
>>> v[:3]
array([4, 7, 1])For question 2: it has three numbers, so it is a 3-dimensional vector, and the book would say it belongs to ℝ³, the set of vectors of three real numbers.
Lesson recap
A vector is a bundle of numbers in a fixed order. Each number is a component; how many there are is the dimension.
A 2-D vector is a point on the plane: the first number steps right, the second steps up.
Bold v, subscript v₁ and ℝ² in books mean a vector's name, a component, and 'all vectors of two real numbers'.
Books count from 1, Python from 0: v₁ = v[0].
Make arrays with np.array and check shape (layout) and dtype (kind of number) first.
In the next lesson you will draw vectors as arrows and learn to add and stretch them. You will also see that + on a Python list and + on a NumPy array do completely different things.
Get news about new lessons
We'll email you when this course gets new lessons or a follow-up course opens.
R
ReflexKR
Learn Python and Reflex by doing. Every example was run and verified on Reflex 0.10.0.
ReflexKR is free, with no banner ads. If it helped you, you can support it with a coffee. ☕ Buy us a coffee
Affiliate disclosure© 2026 ReflexKR · Since 2026 · CC BY-NC 4.0
Questions & answers
Ask anything about this lesson. Questions from every language version of this page appear together.