AI Hints
Statistics & Math for ML · Lesson 76 of 138

Vectors

Lists with direction.

⏱ 2 min read▶ Video at 1:29:49🎓 Free
Watch this lesson in the Statistics & Math for ML courseWatch on YouTube ↗Full Statistics & Math for ML course

In machine learning, everything becomes a list of numbers. A house is its size, rooms, and age. An image is its pixel values. A word can be three hundred numbers. A list of numbers like that is called a vector.

Vectors
From the video: Vectors
  • Everything becomes numbers
  • A house, an image, a word
  • A vector

Vectors in NumPy

A vector is just a one dimensional NumPy array. This house is a hundred and twenty square metres, with four rooms, and ten years old. Its shape is three, so it lives in three dimensional space. Each position always means the same feature. Run it.

vector.pypython
import numpy as np

house = np.array([120, 4, 10])

print(house)
print("shape:", house.shape)
print("rooms:", house[1])
Output
[120   4  10]
shape: (3,)
rooms: 4

Two ways to picture a vector

You can think of a vector as a point in space, like a dot on a map at position three, two. Or as an arrow from the origin to that point, with a length and a direction. Both pictures are useful. With three hundred numbers we can't draw it, but the same maths still works.

keyvalue
Vectoran ordered list of numbers
As a pointa position in space
As an arrowlength and direction
Dimensionshow many numbers

Summary

A vector is an ordered list of numbers, a point or an arrow in space. Every data row is a vector. Next, adding and scaling vectors.

Key takeaways
  • np.array([...])
  • shape = dimensions
  • Point or arrow
Next up: Vector Arithmetic — add and scale