The Ultimate NumPy Cheatsheet (Interactive)

This comprehensive cheat sheet provides interactive examples for learning NumPy, the fundamental Python library for numerical computing and array operations.

import numpy as np

The NumPy ndarray Object

The core of NumPy is the ndarray, an efficient, fixed-size, homogeneous array.

Key ndarray Attributes


Data Types and Type Casting

Specifying dtype on Creation

Casting Data Types

Type Promotion in Operations

Type Promotion: How types are promoted during operations (e.g., int + float = float)

Data Type Affecting Function Behavior

Real and Imaginary Parts


Array Creation

From Existing Data & Sequences

Initial Placeholders

Meshgrid Arrays


Indexing, Slicing, and Subsetting

1D Arrays Indexing & Slicing

2D Arrays Indexing & Slicing

Fancy and Boolean Indexing

Views vs. Copies

Understanding Views and Copies: Slices create views, while boolean/fancy indexing creates copies.


Array Manipulation

Reshaping

Combining and Splitting


Vectorized Expressions and Operations

Element-wise Operations (UFuncs)

Aggregate Functions

Matrix and Vector Operations


Implementation Notes

This content was originally designed with interactive JavaScript modals for each clickable term. In the Markdown version, you can implement interactivity by:

  1. Adding click handlers to code elements for showing explanations
  2. Creating collapsible sections for detailed examples
  3. Using JavaScript to generate dynamic examples
  4. Implementing tooltips for inline explanations

Interactive Features (Future Implementation)


This NumPy cheatsheet covers the essential concepts and operations you'll need for scientific computing and data science applications.

Updated: January 15, 2025
Author: Danial Pahlavan
Category: Data Science & Scientific Computing