Skip to content

NumPy

Beginner → Intermediate · 5 topics

NumPy is Python's library for fast maths on arrays of numbers. Every embedding, every similarity score and every model weight in GenAI is a NumPy-style array — and pandas, scikit-learn and PyTorch are all built on the same ideas.

pip install numpy          # or: uv add numpy
# Topic Sub-topics
1 Arrays Creating arrays · dtype · shape & reshape · arange, linspace, zeros · random numbers
2 Indexing & slicing Rows & columns · boolean masks · fancy indexing · views vs copies · np.where
3 Maths & broadcasting Vectorised maths · aggregations with axis · broadcasting rules · sorting & argmax
4 Linear algebra Dot product · matrix multiply · norms · normalising vectors · stacking
5 NumPy for GenAI Embeddings matrix · cosine similarity · top-k search · softmax & temperature · saving vectors

Why NumPy is fast

A Python for loop handles one number at a time. NumPy runs the same operation over the whole array in optimised C code — often 10–100× faster — so "no loops over numbers" is the main habit to learn.

Next: Pandas — tables of data, built on NumPy.