Matrices as Tables

A matrix is a rectangular table of numbers.

For example:

A=[2113]A = \begin{bmatrix} 2 & 1 \\ -1 & 3 \end{bmatrix}

This matrix has two rows and two columns.

The row-column layout is not decoration. It tells us where each number sits and what role that number can play in later computations.

Entries

Each number is an entry.

We write aija_{ij} for the entry in row ii and column jj.

In this matrix:

a11=2a_{11} = 2

and:

a21=1a_{21} = -1

The first subscript names the row. The second subscript names the column.

MATH-C03-T02-001Exercise: Read an entry

For

A=[2113]A = \begin{bmatrix} 2 & 1 \\ -1 & 3 \end{bmatrix}

what is a21a_{21}?

Compute it first, then check your number.

HintRow first

Go to row 2, then column 1.

SolutionRow 2, column 1

Row 2 is [-1, 3]. The first entry in that row is -1, so a21=1a_{21} = -1.

Rows And Columns

A row runs left to right.

A column runs top to bottom.

For the same matrix:

A=[2113]A = \begin{bmatrix} 2 & 1 \\ -1 & 3 \end{bmatrix}

the first row is:

[2, 1]

and the second column is:

[1, 3]
MATH-C03-T02-002Exercise: Read a column

In the matrix above, what is the second entry of the second column?

Compute it first, then check your number.

HintColumn direction

A column is vertical.

SolutionSecond column

The second column contains the entries from column 2:

[1, 3]

Its second entry is 3.

Why Tables Matter

Tables appear everywhere in machine learning.

  • A dataset can be a table of examples and features.
  • A batch can be a matrix of input vectors.
  • A weight matrix can hold many learned parameters.
  • An attention score table can compare many tokens with many tokens.

The table is not the whole story, but it gives the numbers a shape.

There is one important caution. A matrix can be read as a table, but a table is not automatically a matrix in the useful mathematical sense. The rows and columns need consistent meanings.

For example, adding a table of house features to a table of medical features would be arithmetic without interpretation, even if both tables had the same shape.

MATH-C03-T02-003Exercise: Name the safer reading

Enter 1 if this is the safer reading:

A matrix is a table.
Its rows and columns
give structure to the numbers.

Enter 2 for:

A matrix is only
a long list
written with brackets.

Compute it first, then check your number.

HintKeep the structure

Ask whether row and column position matter.

SolutionStructure matters

Enter 1. A matrix is a table with row-column structure. That structure controls how later computations are read.

MATH-C03-T02-004Exercise: Check table meaning

Enter 1 if two matrices with the same shape can still be a bad match for addition when their rows and columns mean different things.

Compute it first, then check your number.

HintShape is not meaning

Ask what each row and column represents.

SolutionSame shape, different table

Enter 1. Two matrices can have the same number of rows and columns while storing different kinds of quantities. Meaningful operations need matching structure, not just matching shape.

Next, we name the shape of a matrix.