NumPy
The foundational Python library for fast numerical arrays.
CurrentintermediateGuide only -- no course yet
Overview
NumPy provides a fast, multi-dimensional array type and vectorized math operations, implemented in C underneath Python -- it's the performance foundation nearly every other Python data/ML library (Pandas, SciPy, scikit-learn) is built on top of.
- What it is
- A Python library providing fast, multi-dimensional numerical arrays and vectorized operations.
- Why it's used
- Plain Python loops over numbers are slow; NumPy operations run in compiled C code, often 10-100x faster for numerical work.
- Where it fits
- The base layer under Pandas, SciPy, and most Python machine learning libraries.
Core concepts
- The ndarray type
- Vectorized operations (no explicit loops)
- Broadcasting
- Indexing and slicing
Example
prices * 0.9 applies the multiplication to every element at once (vectorization) -- no explicit for loop needed, and it runs far faster than one would.
import numpy as np
prices = np.array([10, 20, 30])
discounted = prices * 0.9
print(discounted) # [9. 18. 27.]Common use cases
- Numerical computation
- The foundation for Pandas, SciPy, and ML libraries
Project ideas
- Compute basic statistics (mean, standard deviation) over a numeric dataset using only NumPy