Skip to content
Tutorials Center
My learning

Topics

Lesson 24 of 62 ยท Vector Spaces

Basis and Dimension

Learn what a basis is, how to find coordinates in any basis, how dimension counts the free directions of a space, and how to test bases with NumPy.

A basis is a minimal set of building blocks for a space. Every vector in the space can be built from the basis vectors in exactly one way, and none of the blocks is redundant. The standard axes (1, 0) and (0, 1) are the basis you already know for the plane, but they are far from the only choice. Picking a different basis changes the numbers you write down for a vector without changing the vector itself.

This lesson combines two ideas from earlier: span, which asks what you can reach, and linear independence, which asks whether any vector is wasted. A basis is a set that does both jobs at once. Counting its vectors gives the dimension of the space.

A basis does two jobs

It spans Every vector in the space can be reached.
It is independent No vector is a combination of the others.
Unique recipe Each vector has exactly one set of coordinates.

Spanning alone can waste vectors. Independence alone can miss directions.

1 / 2

The definition

A set of vectors b1, b2, ..., bk is a basis of a space V when two conditions hold.

  1. They span V. Every vector in V is a linear combination of b1, ..., bk.
  2. They are linearly independent. The only combination that gives the zero vector is the one with all weights equal to zero.

The standard basis of R^3 is e1 = (1,0,0), e2 = (0,1,0), e3 = (0,0,1). But (1, 1) and (1, -1) also form a basis of R^2: they point in different directions, so neither is a multiple of the other, and together they reach every point of the plane.

Why both conditions? Take (1, 0), (0, 1) and (1, 1) in the plane. They span the plane, but (1, 1) is the sum of the other two, so the recipe for a vector is not unique. Take only (1, 0). It is independent, but it spans just a line. A basis sits exactly between "too few" and "too many".

Coordinates in a basis

Suppose the columns of a matrix B are a basis of R^n. For any vector v, the weights c that satisfy B c = v are the coordinates of v in the basis B. Because a basis is independent and spanning, this system has exactly one solution for every v. That is the "unique recipe" idea in matrix form, and B is invertible: c = B^-1 v.

In practice you solve the system rather than invert the matrix, as covered in Solving Systems with NumPy.

Python Coordinates of a vector in a new basis

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

The coordinates are (2, 1): the vector (3, 1) is two copies of (1, 1) plus one copy of (1, -1). In the standard basis the same vector is written (3, 1). The arrow in the plane did not move; only the description of it changed.

Testing whether vectors form a basis

Put the candidate vectors in the columns of a matrix M with m rows and n columns, and compute the rank (see Rank for the full story). The rank is the number of independent columns, so:

  • the columns span R^m when rank == m,
  • the columns are independent when rank == n,
  • the columns are a basis of R^m when rank == m == n, which means M is square and invertible.
Python Which sets are bases?

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Read the four rows as four stories:

  • e1, e2 is a basis: it spans and is independent.
  • The parallel pair has rank 1. The second column is twice the first, so it adds no new direction.
  • Three vectors in R^2 span the plane but cannot be independent: you cannot fit three independent directions in two dimensions.
  • Two vectors in R^3 are independent but only span a plane inside the 3D space.

Dimension

All bases of a space have the same number of vectors. That number is the dimension, written dim V. This is a real theorem, not a convention: if one basis of a plane had two vectors and another had three, you could use one to show the other has dependent vectors, a contradiction.

Some useful facts follow.

  • dim R^n = n.
  • In an n-dimensional space, any n independent vectors form a basis, and any n spanning vectors form a basis. Once the count is right, you only need to check one of the two conditions.
  • Any set with more than n vectors is dependent. Any set with fewer than n vectors cannot span.
  • A subspace has dimension at most that of the space around it. A plane through the origin in R^3 has dimension 2; the zero subspace has dimension 0 and its basis is the empty set.

The span of a set of vectors has dimension equal to the rank of the matrix whose columns they are. That is how you measure the size of a subspace in code.

Python
import numpy as np

# Three vectors, but the third is the sum of the first two
M = np.array([[1, 0, 1],
              [0, 1, 1],
              [1, 1, 2]])
print(np.linalg.matrix_rank(M))   # 2: they span a plane, dimension 2

Dimension counts independent directions, not the number of coordinates used to write a vector. A plane tilted inside R^3 has vectors with three coordinates, but its dimension is 2.

Changing the basis

Different bases give different coordinates for the same vector. Suppose B_old and B_new are two bases of R^2 and x is a vector written in standard coordinates. Then c_old = B_old^-1 x and c_new = B_new^-1 x. To jump straight from old coordinates to new ones, multiply by P = B_new^-1 B_old:

c_new = P c_old

Python Same vector, two coordinate systems

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Both coordinate lists describe the point (4, 3). In the old basis it is 2 * (2, 0) + 3 * (0, 1). In the new one it is 1 * (1, 0) + 3 * (1, 1). The change matrix P converts one recipe into the other. Later, in Change of Basis, you will use the same idea to rewrite entire matrices in a new basis.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. Which pair of vectors is a basis of the plane?

    (1, 2) and (2, 1) point in different directions, so they are independent and, being two vectors in a 2D space, span it. The first pair is parallel, the second contains the zero vector, and a single vector cannot span the plane.
  2. 2. A matrix with 4 columns in R^3 has rank 3. What can you conclude?

    Rank 3 equals the number of rows, so the columns span R^3. Four vectors in a 3-dimensional space must be dependent, so they cannot be a basis.
  3. 3. What is the dimension of the span of (1, 0, 1), (0, 1, 1) and (1, 1, 2)?

    The third vector is the sum of the first two, so only two directions are independent. The span is a plane, dimension 2.
  4. 4. In the basis with columns (1, 1) and (1, -1), what are the coordinates of (3, 1)?

    2 * (1, 1) + 1 * (1, -1) = (3, 1), so the weights are (2, 1).

Summary

  • A basis is a spanning, linearly independent set; every vector has exactly one coordinate list in it.
  • Coordinates in a basis B come from solving B c = v.
  • All bases of a space have the same size, called the dimension. R^n has dimension n.
  • Use np.linalg.matrix_rank to test spanning (rank == rows), independence (rank == columns) and basis-hood (both).
  • Changing the basis changes the numbers but not the vector; P = B_new^-1 B_old converts coordinates.

Next, see how a matrix creates its own important subspaces in Column Space and Null Space.