Gradient
Lesson 3.3Math~50 min

Matrices transform space

A grid of numbers is a machine that stretches, rotates and squishes space.

Module 3 · 0/7 done

A grid of numbers

A matrix is a rectangle of numbers — rows and columns, like a spreadsheet. Its shape is written rows × columns: this one is 2 × 3.

A=[1203−12]A = \begin{bmatrix} 1 & 2 & 0 \\ 3 & -1 & 2 \end{bmatrix}

You’ve already met one: a dataset. One row per example, one column per feature. In code it’s just an array of arrays.

Try itA dataset is a matrix
// A dataset is a matrix: one row per example, one column per feature.
const houses = [
  // size  rooms  age
  [  60,    2,    30],
  [  95,    3,    12],
  [ 120,    3,     5],
  [ 150,    4,     2],
]
console.log("shape:", mat.shape(houses))     // [rows, columns]
console.log("the 3rd house:", houses[2])
console.log("every house's size:", mat.col(houses, 0))
Press Run (⌘/Ctrl + Enter) to see output here.