R

ReflexKR

Reflex Docs

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

Linear Algebra You Can See, with NumPy
Lesson 1

Time 0:00–0:50

Writing the world as lists of numbers: vectors and NumPy arrays

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.

1-1. A bundle of numbers is a vector (10 min)

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 recordsThe numbersDimension
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 photoone brightness per pixel784

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.

1-2. A point on the plane = two numbers (10 min)

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.

32P
32

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)
Drag point P and the numbers on the right change. Turn off 'Snap to grid' to make decimals like 3.5, and watch the NumPy panel below switch the dtype from int64 to float64 at that moment.

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.

1-3. Reading the book's notation (8 min)

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 writesRead it asMeaningIn Python
v\mathbf{v} (bold)vector vthe name given to one bundle of numbersv = np.array([3, 2])
v⃗\vec{v} (arrow)vector vsame meaning, mostly used in handwritingsame as above
v1, v2v_1,\ v_2v one, v twothe first and second components of vv[0], v[1]
R\mathbb{R}R, the real numbersevery number, decimals includedfloat
R2\mathbb{R}^2R twoall vectors of two real numbers = the planean array with shape (2,)
v∈R3\mathbf{v} \in \mathbb{R}^3v is in R threev is a vector of three real numbersv.shape == (3,)

A column vector is written like this.

p=[32],p1=3,p2=2\mathbf{p} = \begin{bmatrix} 3 \\ 2 \end{bmatrix}, \qquad p_1 = 3,\quad p_2 = 2

One thing to watch out for: books count from 1, Python counts from 0. The book's p1p_1 is Python's p[0]. Mistakes from this difference are very common, so keep it in mind from the start.

1-4. Building bundles of numbers with NumPy (15 min)

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 numpy

By 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.])

1-5. Common mistakes (5 min)

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 type

Counting 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 2

Exercises (7 min)

  1. Make the point (−2, 1.5) into a NumPy array a. Predict a.shape and a.dtype first, then check.
  2. What dimension is the color (255, 128, 0)? Using the book's notation, which set does it belong to?
  3. From v = np.array([4, 7, 1, 9]), take out the last component and the first three components.

Solutions

>>> 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.

← Previous

Course overview

Next →

Lesson 2 · Vector = arrow = list of numbers: addition and scaling

Get news about new lessons

We'll email you when this course gets new lessons or a follow-up course opens.

We collect: your email address · Purpose: news about new lessons or the launch of this course · Kept until: you ask us to remove it. We never use it for anything else or share it. Reply to any notice email and we'll delete it right away.

Questions & answers

Ask anything about this lesson. Questions from every language version of this page appear together.

Shown as plain text, without links or formatting.

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
한국어English

© 2026 ReflexKR · Since 2026 · CC BY-NC 4.0

Built with Reflex