NumPy: why a Python loop is expensive
Python is a slow language for numerical work. Each loop iteration: the interpreter checks types, finds objects in memory, runs an operation, returns a new object. On a million elements that is hundreds of milliseconds. NumPy does the same in milliseconds — because under the hood it is compiled C working on a contiguous block of typed memory.