~/talk

Vectorize all the things! Using linear algebra and NumPy to make your Python code lightning fast

Talkat Python Web Conf 2023 · 2023-03-13..03-17· [python]
slides:none on file

Builds a working k‑nearest neighbors classifier in plain Python then replaces slow nested loops and list operations with NumPy arrays, vectorized subtraction, broadcasting and array-based sorting to cut runtime massively. Baseline timings: ~15s (small), 12min (medium), 38min (large). After elementwise NumPy ops: ~8s / 7min / 9min; after 3D broadcasted differences: ~1.5s / 1min / 3min; after stacking + array sort/slicing: ~13ms / 15s / 2.5min — roughly 10–13× speedup on large, ~50× on medium, 1000× on small.

AI-written summary · about

  1. 0:00Introduction and motivation
  2. 1:29Linear algebra basics
  3. 8:28K nearest neighbors explained
  4. 11:34Baseline unoptimized implementation
  5. 16:10Vectorizing distance calculations
  6. 21:09Broadcasting for pairwise distances
  7. 28:56Optimizing K nearest neighbors
  8. 32:30Why arrays outperform lists
~/search
type to search 6,249 conferences, 138,987 speakers and 185,172 talks
~/help
cmdctrl k
search every conference, speaker and series
/
focus the filter search
h
home
c
conferences
s
speakers
e
series
t
light / dark — the status bar button does the same
?
this help
esc
close this, then clear every filter — or just the search, while you are typing in it

Ignored while you are typing. Pages without a filter rail have no search to focus.