Загрузка...

NumPy: How Python Gets C Speed

NumPy isn't really Python. It's a thin Python layer over a C core.

A Python for-loop summing 100 million numbers takes 92 seconds. `np.arange(100_000_000).sum()` finishes in a third of a second — 300× faster, using the same Python you just wrote. Where did the speed come from? Python didn't suddenly get fast. The loop moved into C.

→ Why a Python list is a pointer chase and an ndarray is a wall of bytes
→ What a ufunc actually is, and why `arr + arr` becomes ONE C function call, not a million
→ How NumPy ships hand-tuned SIMD kernels (SSE, AVX, NEON) for every modern CPU
→ The stride trick: why `arr[::2]` doesn't copy — and why broadcasting is literally `stride = 0`
→ The "Python mask over C" pattern that powers pandas, PyTorch, scikit-learn

By the end, that one-line `.sum()` is the least mysterious thing in your data science stack.

Previous video (recommended first): "Why Python Is 100x Slower Than C"

Chapters:
0:00 Intro
0:02 The puzzle — one line, 80× faster
0:38 Bytes, not objects — the memory layout trick
1:33 Ufuncs — one call, one C loop
2:37 Strides — slicing without copying
3:30 The Python mask over C
4:19 Outro

References:
→ Harris et al. "Array programming with NumPy" (Nature 2020) — https://www.nature.com/articles/s41586-020-2649-2
→ NumPy official internals docs — https://numpy.org/doc/stable/reference/internals.html

#Python #NumPy #DataScience

Видео NumPy: How Python Gets C Speed канала Neural Download
Яндекс.Метрика
Все заметки Новая заметка Страницу в заметки
Страницу в закладки Мои закладки
На информационно-развлекательном портале SALDA.WS применяются cookie-файлы. Нажимая кнопку Принять, вы подтверждаете свое согласие на их использование.
О CookiesНапомнить позжеПринять