NumPy Arrays
NumPy's ndarray is a homogeneous n-dimensional array enabling efficient vectorized computation.
Definition
np.array([1, 2, 3]) creates a 1-D array; np.zeros((3, 4)) creates a 3×4 matrix of zeros.
Broadcasting rules let you add a 1-D array to a 2-D array along compatible dimensions without explicit tiling.
Intuition
NumPy operations run in C under the hood — they're orders of magnitude faster than Python for-loops.
NumPy arrays have a dtype and strides; views can be non-contiguous. Layout and vectorization affect speed.
Worked example
np.mean(arr), np.std(arr), np.sum(arr) compute statistics in one call across the whole array.
arr[arr > 5] filters an array to only elements greater than 5 (boolean indexing).
The math
np.dot(a, b) computes the dot product; np.matmul(a, b) or a @ b computes matrix multiplication.
np.linalg.solve(A, b) solves the linear system Ax = b directly, faster and more numerically stable than computing A⁻¹.
In practice
Foundation for all numerical computing in Python: pandas uses it, scikit-learn uses it, deep learning frameworks use it.
Used for manual implementations of algorithms when you need full control over the math.
More in Data science
Assembled from the ReLU.chat curated knowledge base. These explanations are concise on purpose; check the sources for anything important.