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
- Count how many times the Python interpreter is involved in each version.
- 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.
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
- Complete the statement about where a Taylor polynomial works best.
- Select every reason Taylor series matter for computing.
- Libraries compute sin(x) from a polynomial rather than from any geometric definition. Why is a polynomial the…
- Order what the successive Taylor terms make the polynomial match, starting from the centre.