Computer Science I / Taylor Series and Approximation
Practice question · Multiple choice

A NumPy operation on a million-element array runs fifty times faster than the equivalent Python loop, performing identical arithmetic. Where does the time go in the loop?

Hints
  1. Count how many times the Python interpreter is involved in each version.
  2. The arithmetic is identical. Ask what surrounds each operation.
Show the answer

B. Into interpreter overhead per element: dispatch, type checks, boxing

Why

A million interpreter round-trips against one, plus contiguous memory and SIMD in the compiled loop. None of the speedup comes from doing less arithmetic, which is why 'vectorise it' is the first optimisation in scientific Python and means nothing in C.

Read the lesson: Taylor Series and Approximation →

Practise Taylor Series and Approximation

The app has 6 more questions on this lesson, and keeps your place in the course. Computer Science I is free to start.

More questions on Taylor Series and Approximation