Arrays and types

Why NumPy is fast, the many ways to create arrays, and how dtypes decide what an array can hold and how arithmetic behaves.

About 5 hours of study

Learning objectives

Lessons

  1. 1

    Why NumPy Intermediate

    What NumPy is, how its arrays differ from Python lists, why whole-array operations are fast, and how this course models NumPy in plain Python so every exercise runs in your browser.

  2. 2

    Creating arrays Intermediate

    The ways to make arrays: from lists with np.array, filled with zeros, ones or a value, evenly spaced with arange and linspace, identity matrices with eye, and choosing the shape and dtype as you create them.

  3. 3

    Data types: dtype Intermediate

    Why every array has one dtype, the common types (bool, integers, floats), how NumPy chooses the dtype of a result, converting with astype, and the surprises of fixed-size integers and floats.

Module practice

Module quiz

1. Why are NumPy arrays faster than lists for arithmetic?
2. What does np.arange(2, 10, 3) give?
3. What is the dtype of np.array([1, 2.5])?
4. How many values does np.linspace(0, 1, 5) give, and does it include 1?
5. What does astype(int) do to 2.9?
6. Why can int8 arithmetic give surprising results?

Indexing and memory ›