Practice question · Fill in the blanks
Complete the reason vectorised code is faster.
A vectorised array operation beats an explicit loop because it ______.
Word bank: performs fewer arithmetic operations overall · hands the whole array to optimised compiled code · skips most of the elements · uses far less memory
Hints
- Count the additions each version performs, they are the same.
- The difference is in what executes them, not how many there are.
Show the answer
A vectorised array operation beats an explicit loop because it hands the whole array to optimised compiled code.
Why
The arithmetic is identical; the gain comes from replacing interpreted per-element work with compiled code that can process many elements per cycle. Believing that fewer operations are performed is the standard misunderstanding.
Practise Vectorised Computation and Libraries
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 Vectorised Computation and Libraries
- Monte Carlo error falls like 1/√(N) regardless of the dimension, which is why it wins in high dimensions.
- A Monte Carlo simulation run twice with different random seeds gives two different answers. Why is that a…
- An interpreted loop processes 2 million elements per second while the vectorised version processes 500…
- Sort each code pattern by its style.
- Monte Carlo error falls like 1/√N. To gain one more decimal digit of accuracy, what does that cost?