NumPy is the fundamental library for scientific computing in Python. Its core contribution is theDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/ageron/handson-ml3/llms.txt
Use this file to discover all available pages before exploring further.
ndarray — an N-dimensional array object that enables fast, vectorized numerical operations. Every ML notebook in this series depends on NumPy, from loading data to computing gradients. Understanding NumPy well saves you from slow Python loops and enables you to work efficiently with the large matrices that appear throughout machine learning.
Creating arrays
The most common way to import NumPy is:np.zeros, np.ones, np.full
Create arrays filled with a constant value.
Array shape vocabulary
Every array has ashape, ndim, and size:
np.arange and np.linspace
np.arange works like Python’s range, while np.linspace is safer for floats because it guarantees an exact count of elements:
Random arrays
NumPy’srandom module is used throughout the ML notebooks to generate synthetic data and initialise weights:
Indexing and slicing
NumPy arrays support standard Python slicing notation, extended to multiple dimensions:Broadcasting
Broadcasting is NumPy’s mechanism for performing element-wise operations on arrays with different shapes without copying data. The rule is: dimensions are compared from the trailing (rightmost) axis. Two dimensions are compatible if they are equal or one of them is 1.Vectorized math operations
NumPy operations apply element-wise by default; no loops required:Dot products and matrix multiplication
The@ operator (available since Python 3.5 / NumPy 1.10) computes matrix products and dot products. np.dot does the same:
np.linalg — linear algebra utilities
The numpy.linalg module provides the core linear-algebra operations used in ML:
Reshaping and transposing
Converting to/from Python lists
In the notebooks,
arr.to_numpy() appears on Pandas DataFrames and Series — that converts a Pandas object to a NumPy array. For plain NumPy arrays use .tolist() or simply pass the array directly to functions that accept ndarrays.