Matrices as Tables
A matrix is a rectangular table of numbers.
For example:
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 for the entry in row and column .
In this matrix:
and:
The first subscript names the row. The second subscript names the column.
For
what is ?
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
.
Rows And Columns
A row runs left to right.
A column runs top to bottom.
For the same matrix:
the first row is:
[2, 1]
and the second column is:
[1, 3]
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.
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.
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.