Practice question · Multiple choice
Vectorising usually gives a large speed-up, but sometimes almost none. Why does replacing a loop with an array operation sometimes fail to help?
Hints
- Try to vectorise .
- Ask what the machine is waiting for when the arrays are enormous.
Show the answer
A. When each step depends on the previous result, or memory is the limit
Why
Vectorising removes per-iteration interpreter overhead. Where that overhead was not the bottleneck — a genuine dependency chain, or a memory-bound operation — there is nothing for it to remove.
Practise Reproducibility and Good Practice
The app has 5 more questions on this lesson, and keeps your place in the course. Mathematics I is free to start.
More questions on Reproducibility and Good Practice
- A NumPy vectorised operation and an equivalent Python loop compute identical results, and the vectorised one…
- A colleague sends a script and the number it printed. Select everything you still need before that result can…
- Two runs of the same simulation with the same fixed seed and the same library versions should produce…
- Sort each practice by its effect on reproducibility.
- Complete the purpose of a test suite.
- A test suite contains 40 unit tests, of which 36 passed before a change. The change makes 3 previously…
- Order the steps of putting an analysis on a reproducible footing.