Search⌘ K
AI Features

Column Space

Learn to define and compute the column space of a matrix, identify its basis via reduced row echelon form, and understand its role in linear transformations, vector spaces, and consistency of linear systems in data science.

Definition

The column space of a matrix, AA, often denoted by C(A)C(A), is a vector space spanned by the column vectors of AA.

The column-space of an m×nm \times n matrix AA is a subspace of Rm\R^m. The dimensions of the column space are the number of linearly independent columns, that is, the rank of the matrix AA.

Examples

  1. The column space of [1001]\begin{bmatrix}1 &0\\0&1\end{bmatrix} is R2\R^2.

  2. The column space of [1224]\begin{bmatrix}1 &2\\2&4\end{bmatrix} is a one-dimensional subspace of R2\R^2. This is because there’s a single linearly independent vector as 2c1=c22\bold{c_1} =\bold{c_2}. Any of these columns can be a basis for the subspace.

  3. The column space of [0000]\begin{bmatrix}0 &0\\0&0\end{bmatrix} is a zero-dimensional subspace of R2\R^2.

  4. The column space of an n×nn \times n invertible matrix AA is Rn\R^n. This is because all the columns of such a matrix are linearly independent. That is, rank(A)=nrank(A)=n.

The columns of every n×nn \times n invertible matrix form a basis of RnR^n.

Basis of column space

A basis of the column space of a matrix, AA, is a set of linearly independent columns of AA. One algorithm for computing the basis is as follows:

  1. Take the transpose of the matrix to convert the columns into rows.

  2. Compute the rrefrref (reduced row echelon form) of the transposed matrix.

  3. The set of non-zero rows in rrefrref is a linearly-independent set. These form the basis of the column space.

Note that the basis found by the algorithm above may not contain the original column vectors, but their linear combinations as elementary row operations have transformed the matrix into rrefrref.

Let’s try it out by using the following code:

Python 3.8
from sympy import *
import numpy as np
# Function to find the basis of column space of A
def basisOfColumnSpace(A):
rref , idx = Matrix(A.T).rref()
rref = np.array(rref, dtype=np.float32)
r = np.linalg.matrix_rank(rref)
basis = rref.T[:, :r]
return basis
A = np.array([[1, 3, 5],
[2, 6, -1],
[6, 18, 4]])
basis = basisOfColumnSpace(A)
print(f'The columns of\n{np.round(basis, 2)}\nform a basis of column space of\n{A}')

Verifying a basis of column space

Given a set, BB, of linearly-independent vectors from Rm\R^m, how do we know that the set is a basis for the column space of a given m×nm \times n matrix AA? To do this, we need to determine the following:

  1. Are all the columns of AA in the span of BB? If they are, it will prove that C(A)span(B)C(A)\subseteq span(B).

  2. Are all the vectors in BB in the column space of AA?. If they are, it will will prove that span(B)C(A)span(B) \subseteq C(A).

Both points above together prove that C(A)=span(B)C(A)=span(B). Here’s one algorithm for this problem:

  1. Create a matrix CC with columns that are the vectors in BB.
  2. Check whether the ranks of AA and CC are equal, say rr.
  3. Create a matrix, DD, with columns of AA and CC (in any order).
  4. If the rank of the matrix, DD, is also rr, then BB is a basis of C(A)C(A).

The code below implements the algorithm above.

Python 3.8
import numpy as np
from numpy.linalg import matrix_rank as rank
# Function to verify if B is a basis of column space of A
# B is a list and A is a matrix
def isBasisOfColumnSpace(B, A):
C = np.zeros((A.shape[0], len(B)))
for i in range(len(B)):
C[:, i] = B[i]
if rank(C) != rank(A):
return False
D = np.hstack((A, C))
if rank(D) != rank(A):
return False
return True
# Candidate basis
B = [[1, 2, 6], [10, -2, 8]]
# Matrix A
A = np.array([[1, 3, 5],
[2, 6, -1],
[6, 18, 4]])
rs = ['B is not basis of C(A)', 'B is basis of C(A)']
print(f'{rs[isBasisOfColumnSpace(B, A)]}')

Column space and linear transformation

The multiplication of a matrix with a vector can be viewed as a linear transformation of the vector. Consider an m×nm \times n matrix AA and a vector, wRn\bold w \in \R^n. If we look closely at the matrix, AA, represented in column vectors as A=[c1c2cn]A=\begin{bmatrix}\bold c_1 &\bold c_2&\cdots &\bold c_n\end{bmatrix} and the vector w\bold w in its individual components, namely w=[w1w2wn]T\bold w=\begin{bmatrix}w_1 &w_2&\cdots &w_n\end{bmatrix}^T, then

Aw=w1c1+w2c2++wncnC(A)A\bold w=w_1\bold c_1+w_2\bold c_2+\cdots+w_n\bold c_n \in C(A)

Note: A linear transformation matrix, AA, maps every vector to the column space of AA.

Examples

  1. The column space of A=[1313]A=\begin{bmatrix} 1 & 3\\-1 & -3\end{bmatrix} is a line through the origin in the direction of the vector, [11]T\begin{bmatrix}1 &-1\end{bmatrix}^T. If matrix AA is multiplied with any vector in R2\R^2, it maps the vector onto that line. Below is its visualization:
  1. The column space of A=[112212012]A=\begin{bmatrix} 1 & 1 & -2 \\-2 & 1 & -2 \\0 & 1 & -2\end{bmatrix} is a plane through the origin in R3\R^3, with the first 22 column vectors as the basis. The visualization below shows how all the vectors on a cube map onto the plane when transformed using AA. This is true for every vector in R3\R^3.
  1. The column space of A=[121212013]A=\begin{bmatrix} 1 & 2 & -1 \\-2 & 1 & 2 \\0 & 1 & 3\end{bmatrix} is R3\R^3, but the standard basisStandard basis of a vector space is the basis where each vector has exactly one non-zero value equalling 1. of R3\R^3 (represented by a 3×33 \times 3 identity matrix) transforms to the columns of the matrix. The visualization below shows all the vectors on a cube transforming to other vectors but not collapsing to any plane or a line. This is also true for all the other vectors in R3\R^3.

A linear system, Ax=bA\bold x=\bold b, is consistent if bC(A)\bold b \in C(A). For invertible coefficient matrices, every vector is in the column space. So, the system is always consistent and an exact solution can be obtained through the inverse of AA. That is, x=A1b\bold x = A^{-1}\bold b.