Read this lesson as text

Vectorized Thinking

Linear Algebra for Machine Learning · Axiom Academy

Why loops are slow and vectorization is fast NumPy operations are implemented in C and execute at the machine level. Python loops execute Python bytecode, which is slower. For 1 million elements, this difference compounds massively. Example: Broadcasting a Scalar Arrays are aligned from the right. Dimensions are compatible if they're equal or one is 1. The dimension of size 1 is stretched to match the other. Loop version: Multiply 1M numbers by 2 = 100ms. Vectorized: Same operation = 1ms. In a deep learning model with billions of operations, this compounds to differences of hours vs minutes. NumPy is optimized for vectorized operations. The faster you can eliminate loops, the faster your code will be. This is crucial for machine learning where you're processing millions of data points.

This is the written version of the interactive lesson above. See the full Linear Algebra for Machine Learning course.