A Complete Guide to Numerical Computing in Python
Introduction
Chapter 1: Why NumPy - The Foundation of Scientific Python
- The Problem with Python Lists for Numbers
- Enter NumPy - A Brief History from Numeric to NumPy
- Installing and Verifying Your Setup
- Your First Array - A Taste of What’s Coming
- How This Book Is Organized
Chapter 2: The ndarray - Understanding NumPy’s Core Data Structure
- What Is an ndarray?
- Dimensions, Shape and Rank
- Data Types - The dtype System
- Memory Layout - Contiguous Arrays in C
- Views Versus Copies - A Critical Distinction
- Inspecting Your Arrays
Chapter 3: Creating Arrays - From Scratch and From Data
- From Python Lists and Tuples
- Generating Sequences with arange and linspace
- Filled Arrays - zeros, ones, empty, full
- Random Initialization Basics
- Identity Matrices and Diagonal Arrays
- From Files and External Data
- Converting Between Types and Shapes During Creation
Chapter 4: Indexing and Slicing - Accessing Array Elements
- Basic Integer Indexing
- Slicing - The start:stop:step Pattern
- Multi-dimensional Indexing and Slicing
- Boolean Indexing and Masking
- Fancy Indexing with Arrays of Indices
- Combining Indexing Strategies
- Common Pitfalls and Gotchas
Chapter 5: Reshaping, Stacking and Splitting - Rearranging Data
- Reshape and resize
- Flatten, Ravel and Squeeze
- Transpose and Axis Swapping
- Stacking Arrays - vstack, hstack, concatenate
- Splitting and Partitioning Arrays
- Broadcasting - The Key to Elegant Array Code
- When Operations Return Views Versus Copies
Chapter 6: Vectorization and Universal Functions - Writing Fast NumPy Code
- The Cost of Python Loops
- What Is Vectorization?
- Universal Functions - Element-wise Operations
- Arithmetic and Comparison Ufuncs
- Logical Operations on Arrays
- Reducing Dimensionality with Aggregations
- Writing Your Own Vectorized Code
Chapter 7: Mathematical and Statistical Computing
- Basic Arithmetic and Powers
- Trigonometric and Exponential Functions
- Rounding, Clipping and Modulo Operations
- Summarizing Data - Mean, Median, Variance, Standard Deviation
- Correlation and Covariance
- Percentiles and Quantiles
- Handling Numerical Precision
Chapter 8: Sorting, Searching and Set Operations
- Sorting Arrays - sort and argsort
- Partial Sorting with Partition
- Searching for Values - where, argwhere, searchsorted
- Finding Unique Elements
- Set Operations - union, intersection, difference
- Comparing Arrays for Equality and Approximation
Chapter 9: Random Number Generation - The np.random Module
- Why Randomness Matters in Scientific Computing
- The Modern Generator API - default_rng
- Seeding for Reproducibility
- Common Distributions - Uniform, Normal, Poisson
- Discrete and Specialized Distributions
- Generating Random Samples Without Replacement
- Best Practices and Common Mistakes
Chapter 10: Linear Algebra with NumPy
- Matrix Multiplication - dot, matmul and the @ Operator
- Transpose, Conjugate and Special Matrices
- Solving Linear Systems
- Determinants, Trace and Rank
- Eigendecomposition
- Singular Value Decomposition (SVD)
- Condition Numbers and Numerical Stability
Chapter 11: Handling Missing Data and Special Values
- What Are NaN and Infinity?
- Detecting Special Values
- nan-aware Functions - nansum, nanmean, etc.
- Masked Arrays for Complex Missing Data Patterns
- Replacing and Cleaning Special Values
- Design Decisions Behind NumPy’s Approach
Chapter 12: Performance Optimization and Memory Efficiency
- Understanding Strides and Memory Layout
- C-contiguous Versus Fortran-contiguous Arrays
- Avoiding Unnecessary Copies
- In-place Operations
- Vectorization Strategies for Complex Problems
- Profiling NumPy Code
- When to Use Numba or Cython Alongside NumPy
Chapter 13: Advanced Topics and Power User Patterns
- Structured Arrays and Record Arrays
- Memory-mapped Files for Huge Datasets
- Advanced Indexing Patterns
- Subclassing ndarray
- Type Annotations with NumPy Arrays
- The NumPy API Design Philosophy
Chapter 14: NumPy in the Ecosystem - Working with Other Libraries
- NumPy and pandas - Arrays Underneath DataFrames
- NumPy and SciPy - From Foundations to Specialized Functions
- NumPy and Matplotlib - Plotting Arrays Directly
- NumPy and scikit-learn - The Array Interface
- Interoperability Patterns Across Libraries
- Choosing the Right Tool for the Job