← All questions
Python & DataEasy· NumPy Essentials

Why is NumPy so much faster than plain Python lists for...

Three things stack together. First, memory layout: a NumPy array is one contiguous block, like a C array, which the CPU cache handles well; a Python list is actually a list of pointers to objects scattered around memory, which the cache handles poorly. Second, the operations themselves are implemented in C and use SIMD instructions to process several elements per CPU instruction, instead of Python’s interpreter looping one element at a time. Third, a NumPy array commits to a single dtype, so there’s no per-element type check on every operation the way a mixed-type Python list requires.

The combined effect is usually a 10-100x speedup on numerical work. The practical takeaway that follows from this is a hard rule: normalizing a million features with a Python list comprehension might take 80ms, where the vectorized NumPy equivalent takes 2ms — and that gap compounds across every batch in a training loop, so a Python loop over numeric data is almost never the right call.

Code playground (Python)