POST 1 of 5 MorningAI/MLConcept
NumPy is C with a Python skin
Day 29. Week five begins, and we leave pure DSA for the data stack — the libraries that turn Python from 'a great teaching language' into the dominant language of machine learning. Let's start with NumPy. Loops in pure Python are slow. Even a simple sum over a million numbers takes hundreds of milliseconds. The same operation in C takes microseconds. The gap is roughly 100x. NumPy closes the gap. Under the hood, an ndarray is a contiguous block of typed memory (32-bit floats, 64-bit ints, etc.) plus a set of C kernels that operate on that memory. When you write 'a + b' on two NumPy arrays, NumPy doesn't run a Python loop — it dispatches to a C function that adds them element-by-element using SIMD instructions where possible. The result — you write one line of Python, you get C-speed execution. This is why every modern ML framework — PyTorch, JAX, TensorFlow — is built on the same ndarray abstraction. PyTorch tensors are essentially NumPy arrays with GPU support and automatic differentiation. JAX arrays are NumPy arrays with JIT compilation and GPU/TPU support. The shape API is the same; the underlying numerical operations are the same; only the execution backend differs. Which means — once you internalise NumPy, you've internalised 80% of how to read PyTorch, JAX, or TensorFlow code. Same patterns. Same vocabulary. Same idioms. The rule for the next 60 days — vectorise or perish. If you find yourself writing a Python for-loop over a NumPy array, stop. There's almost always a vectorised alternative that's 100x faster. When NumPy can't vectorise (rare, usually involves complex stateful logic), use numba or cython to JIT-compile the loop. Last resort, write the inner loop in C++ and bind via pybind11. Pure Python loops over numerical data are something to avoid.
#NumPy#Pandas#DataScience#Python#100DaysOfCode#NumPy