Open workspace
Tools 1.1Code walkthrough7 parts

Why NumPy

Say what an array holds that a list does not, and why that makes it faster and smaller.

Loading your progress…Next: 1.2 Shape, dtype and Reshaping

In this lesson7 parts

  1. 01Summing a list with a Python loop, and timing it
  2. 02Why NumPy, and array oriented computing
  3. 03References, objects and the packed buffer
  4. 04Creating an array with np.array, and summing it
  5. 05How the speed difference scales with array size
  6. 06Fixed width types, and object dtype
  7. 07Recap and your challenge

Quiz 5 questions

Answer each one in your head, or on paper, before you check it. Getting one wrong here is how the lesson sticks.

  1. 01

    Three hundred and sixty five prices take 12016 bytes as a Python list and 2920 bytes as a NumPy array. Where did the difference go?

  2. 02

    Why is the Python loop slower than takings.sum()?

  3. 03

    What does np.array([2 ** 70]) produce?

  4. 04

    At a thousand values, you time three things: the Python loop, arr.sum() on an array you already have, and np.array(values).sum() starting from a list. Which is slowest?

  5. 05

    So when does converting a list to an array pay off?