Index Ai Academy
Foundation · Foundation mathVectors and matrices

Vectors: lists of numbers that point

About 42 minLooking ahead: some prerequisites aren't done yet

Why this matters

A vector is a list of numbers that belong together, like a day's temperature and humidity, or every pixel of a picture. The same list can be read as a point, or as an arrow from the origin, and each view helps in a different way. Vectors are the language of machine learning: every example a model ever sees, and every set of weights it learns, is a vector. This lesson starts the biggest module of the section and brings in its two Python tools: NumPy, and PyTorch, the library most models are built with. By the end you'll read a vector three ways, store one as a NumPy array and as a PyTorch tensor, unroll a small picture into one, and know why a Python list and an array behave so differently when you add them.

  • See a vector three ways: a list of numbers, a point, and an arrow
  • Name a vector's components and its dimension, and know that a moved arrow is the same vector
  • Make vectors with NumPy's np.array, read .shape, and know why a list isn't an array
  • Turn real data into vectors: a day as 2 numbers, a picture as 25, a word as an embedding
  • Make the same vectors as PyTorch tensors, and read their .shape and .dtype
Quick check
Have a guess before you start. An arrow goes from (0, 0) to (3, 2). Which of these is the same arrow, just drawn somewhere else?

The math: one object, three views

Purpose. Hold several numbers that belong together as one thing.

A vector is a list of numbers in order, written in brackets: v = (3, 2). Each number is a component, and the count of them is the dimension: (3, 2) is 2-dimensional, (1, 0, 4) is 3-dimensional. The same vector can be read three ways:

  • as a list: just the numbers, 3 then 2;
  • as a point: over 3, up 2, like lesson 41's coordinates;
  • as an arrow: from the origin to that point, with a length and a direction.

As an arrow, a vector is a movement, "3 across, 2 up". So the same arrow drawn from a different start is still the same vector.