Vectorization: How slow Python runs fast code
summary
Vectorization means using chunked numeric representations and bulk native routines so Python code runs C/Rust-speed on large arrays. Using numpy.sum on a 30 million–element array measures about 100x faster than a Python loop (loop ~1.5s, numpy ~0.03s in the demo). Watch for tradeoffs: creating temporaries (abs(array) then mean) doubles memory; use Numba for in-place loops or avoid per-item callbacks like pandas.map which reintroduce Python overhead.
AI-written summary · about
chapters (22)
- 0:00Intro
- 0:13Why software speed matters
- 1:36Feedback cycle time matters
- 2:27The paradox of Python performance
- 2:59Arrays: a shared, fundamental data structure
- 4:12The vectorization solution
- 5:17An example: Same results...
- 7:01An example: ...different speed
- 8:39Talk is about CPython
- 11:32Iteration in CPython: slow!
- 12:25Doing math in Python: slow!
- 14:59Memory layout of C arrays
- 15:59Memory layout of Python lists
- 16:55Carray vs. Python list
- 17:47NumPy arrays: a better memory layout for numeric data
- 19:19Example: Summing one million integers
- 22:51What does "vectorization" mean?
- 24:47Digression: Single Instruction, Multiple Data (SIMD)
- 27:10Avoiding built-in Python objects: example
- 28:18Avoid iterating in Python
- 31:16Avoid calling back into Python
- 33:29Summary: Writing fast data processing code
related talks
29mVectorize using linear algebra and NumPy to make your Python code fast
34mNumPy: vectorize your brain
01h 31mMaking Computation Easier with Cool Numpy Tricks
28mWhy Python Loops Are "Slow": A Gentle Introduction to Interpretation, Bytecode, and Fast Code
23mPerformance Python: Seven Strategies for Optimizing Your Numerical Code
01h 27mMaking computation easier with cool Numpy tricks
40mSpeed Without Drag
37mUsing Numba Effectively Today
