Chapter 2: NumPy & Data Wrangling
Master NumPy arrays for numerical computing, Pandas DataFrames for data manipulation, and essential data preprocessing techniques including cleaning, scaling, and encoding.
Chapter Overview
NumPy is the foundation of scientific computing in Python. Every image processing, machine learning, and data science library builds on NumPy arrays. Whether you're processing images pixel by pixel, training neural networks, or analyzing tabular datasets, NumPy arrays are at the core.
Why NumPy matters:
- Universal data structure: Images are 2D/3D arrays, feature matrices are 2D arrays, neural network weights are multi-dimensional arrays
- Vectorized operations: Process millions of elements without explicit loops -- 10-100x faster than pure Python
- Memory efficiency: Contiguous storage, typed arrays, views instead of copies
- Interoperability: OpenCV, PyTorch, TensorFlow, scikit-learn all use NumPy-compatible arrays
Pandas builds on NumPy to provide labeled, tabular data structures. A DataFrame is like a spreadsheet in Python: rows represent observations, columns represent features, and you can refer to data by name rather than position. Pandas excels at loading data from various sources, handling missing values, merging datasets, and computing aggregations.
Real-world data is messy. You'll encounter missing values, outliers, inconsistent formats, and features on vastly different scales. Data preprocessing often takes 80% of a data scientist's time, and this chapter teaches the essential techniques.
What you'll learn:
- Array Creation & Operations -- Building arrays, understanding shape/dtype, vectorized computation
- Indexing & Slicing -- Extracting regions, channels, and subsets efficiently
- Broadcasting -- Writing concise code for element-wise operations across different shapes
- Reshaping -- Converting between image formats (HWC, CHW, batched) and data layouts
- Statistics -- Computing histograms, means, distributions, and aggregations
- Linear Algebra -- Matrix operations for transforms, decompositions, and dimensionality reduction
- Pandas DataFrames -- Loading, exploring, filtering, and transforming tabular data
- Data Cleaning -- Handling missing values, outliers, and data quality issues
- Feature Preparation -- Scaling, encoding, and transforming features for ML algorithms
These skills directly apply to every CV and ML task: loading images, preprocessing data, applying filters, preparing features, and feeding data into models.
Chapter Roadmap
Click any topic to jump in
Array Creation
Creating N-dimensional arrays, dtypes, and vectorized operations — the foundation of numerical computing in Python.
Selection and shape alignment
Indexing & Slicing
Basic, advanced, and boolean indexing with views vs copies — efficiently selecting data from arrays.
Broadcasting
How NumPy aligns arrays of different shapes for element-wise operations — eliminating explicit loops.
Geometry and summary statistics
Reshaping
Reshape, transpose, stack, and concatenate — manipulating array geometry without copying data.
Statistics
Mean, std, percentiles along any axis — summarizing data in one vectorized call.
Linear Algebra
Matrix multiply, SVD, eigendecomposition — the core operations behind PCA, regression, and neural networks.
DataFrames, cleaning, and features
Pandas DataFrames
Labeled tabular data with method chaining — the standard for data wrangling in ML.
Data Cleaning
Missing values, outlier detection, and imputation — preparing real-world data for models.
Feature Prep
Scaling, normalization, encoding — transforming raw features into model-ready inputs.
Sign up to unlock this chapter
This chapter is part of PixelBank Premium. Create a free account, then upgrade to read the full lesson — concepts, walkthroughs, and exercises.