NumPy

19 min read

NumPy is a Python library (a box of ready-made tools) for working with big lists of numbers very fast. An embedding, which is a list of numbers for the meaning of a sentence, is just a NumPy array. In this lesson you make arrays, do math on a million numbers at once, and compare two embeddings.

New words

Array
A row or grid of numbers that all have the same type.
Shape
The size of an array: how many rows and columns it has.
Vectorised math
Doing one operation on every item of an array at once, with no loop.
Axis
A direction in a table: axis 0 goes down, and axis 1 goes across.
Broadcasting
The rule NumPy uses to repeat a smaller array so it fits a bigger one.
Dot product
Multiply the matching items of two arrays, then add up the results.
Cosine similarity
A score from -1 to 1 that shows how alike two arrays are.

What you will learn

  1. Why do AI engineers use NumPy?
  2. How do you make arrays?
  3. What are shape and dtype?
  4. How do you pick items from an array?
  5. What is vectorised math?
  6. What are aggregates and axes?
  7. What is broadcasting?
  8. What are dot product and cosine similarity?
  9. Try it: a grid of numbers
  10. Common mistakes
  11. Explain it to a friend
  12. Key takeaways

10 quiz questions at the end.

Start this lesson

The full lesson, with interactive demos and the quiz, opens after you sign in with Google. It is free.

All lessons · Back to the roadmap