Leanpub Header

Skip to main content

NumPy Mastery

A Complete Guide to Numerical Computing in Python

This book is 100% completeLast updated on 2026-08-09

Master NumPy from the ground up and learn to write fast, efficient Python for numerical computing. With clear explanations, practical examples and real-world techniques, this guide takes you from array basics to advanced workflows while helping you understand how NumPy really works.

Minimum price

$19.00

$29.00

You pay

Author earns

$

Also available for 1 book credit with a Reader Membership

PDF
EPUB
WEB
APP
155
Pages
About

About

About the Book

This book takes you from zero experience with NumPy to advanced proficiency in using it for numerical computing, data analysis and scientific programming. You will learn not only how to write correct NumPy code, but also how to write fast, memory-efficient, maintainable code that leverages the full power of arrays. Every concept is explained with complete, runnable examples and grounded in real-world usage patterns. By the end, you will understand why NumPy works the way it does and be equipped to use it confidently as both a learning resource and long-term reference.

Author

About the Author

Steve Publications

Steve is a technology professional with more than 20 years of experience in software development, server infrastructure, cybersecurity, vulnerability research and reverse engineering. Throughout his career, he has designed, secured, analyzed and tested complex software and infrastructure, with a particular focus on understanding how systems fail and how they can be made more secure.

Outside of work, Steve enjoys sharing knowledge with the technology community. He collaborates with researchers, industry experts and technology professionals to write practical books covering software development, cybersecurity, cloud computing, networking, DevOps, artificial intelligence and enterprise technologies. His books focus on practical learning through clear explanations, real-world examples and hands-on exercises. With more than two decades of industry experience, his goal is to help IT professionals, students and technology enthusiasts build useful skills and stay current in a rapidly changing industry.

We believe readers deserve to know how our books are created. Most of our authors are not native English speakers, so we use AI to help translate, proofread manuscripts, fix grammar, improve sentence structure and make technical explanations easier to read. AI is used as an editing tool only. It does not replace the research, technical knowledge or hands-on experience behind our books. Some of our authors also prefer to remain anonymous for privacy or professional reasons. In those cases, we publish their work under a different name. The author's name may be different, but the quality of the content and our review process remain the same.

Every book is written, reviewed and maintained by experienced technology professionals, with contributions from our private technical community of more than 420 engineers and researchers. We spend far more time validating technical accuracy and keeping our content up to date than generating text. We are always interested in working with experienced professionals who have deep expertise in a particular technology or domain. If you would like to publish a book with us or help review an existing manuscript, we'd love to hear from you. Send us a message describing your area of expertise. We are especially interested in niche technologies, specialized skills and emerging topics that are underrepresented in existing technical literature.

If you look through the contents of our books, you'll see practical examples, detailed explanations and material that is regularly updated. Our goal is to publish books that professionals can actually rely on, not low-effort AI-generated content. If you ever feel that one of our books does not meet that standard, Leanpub offers a 60-day money-back guarantee. Feel free to request a refund if you are not satisfied with your purchase.

Contents

Table of Contents

A Complete Guide to Numerical Computing in Python

Introduction

Chapter 1: Why NumPy - The Foundation of Scientific Python

  1. The Problem with Python Lists for Numbers
  2. Enter NumPy - A Brief History from Numeric to NumPy
  3. Installing and Verifying Your Setup
  4. Your First Array - A Taste of What’s Coming
  5. How This Book Is Organized

Chapter 2: The ndarray - Understanding NumPy’s Core Data Structure

  1. What Is an ndarray?
  2. Dimensions, Shape and Rank
  3. Data Types - The dtype System
  4. Memory Layout - Contiguous Arrays in C
  5. Views Versus Copies - A Critical Distinction
  6. Inspecting Your Arrays

Chapter 3: Creating Arrays - From Scratch and From Data

  1. From Python Lists and Tuples
  2. Generating Sequences with arange and linspace
  3. Filled Arrays - zeros, ones, empty, full
  4. Random Initialization Basics
  5. Identity Matrices and Diagonal Arrays
  6. From Files and External Data
  7. Converting Between Types and Shapes During Creation

Chapter 4: Indexing and Slicing - Accessing Array Elements

  1. Basic Integer Indexing
  2. Slicing - The start:stop:step Pattern
  3. Multi-dimensional Indexing and Slicing
  4. Boolean Indexing and Masking
  5. Fancy Indexing with Arrays of Indices
  6. Combining Indexing Strategies
  7. Common Pitfalls and Gotchas

Chapter 5: Reshaping, Stacking and Splitting - Rearranging Data

  1. Reshape and resize
  2. Flatten, Ravel and Squeeze
  3. Transpose and Axis Swapping
  4. Stacking Arrays - vstack, hstack, concatenate
  5. Splitting and Partitioning Arrays
  6. Broadcasting - The Key to Elegant Array Code
  7. When Operations Return Views Versus Copies

Chapter 6: Vectorization and Universal Functions - Writing Fast NumPy Code

  1. The Cost of Python Loops
  2. What Is Vectorization?
  3. Universal Functions - Element-wise Operations
  4. Arithmetic and Comparison Ufuncs
  5. Logical Operations on Arrays
  6. Reducing Dimensionality with Aggregations
  7. Writing Your Own Vectorized Code

Chapter 7: Mathematical and Statistical Computing

  1. Basic Arithmetic and Powers
  2. Trigonometric and Exponential Functions
  3. Rounding, Clipping and Modulo Operations
  4. Summarizing Data - Mean, Median, Variance, Standard Deviation
  5. Correlation and Covariance
  6. Percentiles and Quantiles
  7. Handling Numerical Precision

Chapter 8: Sorting, Searching and Set Operations

  1. Sorting Arrays - sort and argsort
  2. Partial Sorting with Partition
  3. Searching for Values - where, argwhere, searchsorted
  4. Finding Unique Elements
  5. Set Operations - union, intersection, difference
  6. Comparing Arrays for Equality and Approximation

Chapter 9: Random Number Generation - The np.random Module

  1. Why Randomness Matters in Scientific Computing
  2. The Modern Generator API - default_rng
  3. Seeding for Reproducibility
  4. Common Distributions - Uniform, Normal, Poisson
  5. Discrete and Specialized Distributions
  6. Generating Random Samples Without Replacement
  7. Best Practices and Common Mistakes

Chapter 10: Linear Algebra with NumPy

  1. Matrix Multiplication - dot, matmul and the @ Operator
  2. Transpose, Conjugate and Special Matrices
  3. Solving Linear Systems
  4. Determinants, Trace and Rank
  5. Eigendecomposition
  6. Singular Value Decomposition (SVD)
  7. Condition Numbers and Numerical Stability

Chapter 11: Handling Missing Data and Special Values

  1. What Are NaN and Infinity?
  2. Detecting Special Values
  3. nan-aware Functions - nansum, nanmean, etc.
  4. Masked Arrays for Complex Missing Data Patterns
  5. Replacing and Cleaning Special Values
  6. Design Decisions Behind NumPy’s Approach

Chapter 12: Performance Optimization and Memory Efficiency

  1. Understanding Strides and Memory Layout
  2. C-contiguous Versus Fortran-contiguous Arrays
  3. Avoiding Unnecessary Copies
  4. In-place Operations
  5. Vectorization Strategies for Complex Problems
  6. Profiling NumPy Code
  7. When to Use Numba or Cython Alongside NumPy

Chapter 13: Advanced Topics and Power User Patterns

  1. Structured Arrays and Record Arrays
  2. Memory-mapped Files for Huge Datasets
  3. Advanced Indexing Patterns
  4. Subclassing ndarray
  5. Type Annotations with NumPy Arrays
  6. The NumPy API Design Philosophy

Chapter 14: NumPy in the Ecosystem - Working with Other Libraries

  1. NumPy and pandas - Arrays Underneath DataFrames
  2. NumPy and SciPy - From Foundations to Specialized Functions
  3. NumPy and Matplotlib - Plotting Arrays Directly
  4. NumPy and scikit-learn - The Array Interface
  5. Interoperability Patterns Across Libraries
  6. Choosing the Right Tool for the Job

Conclusion

References

Get the free sample chapters

Click the buttons to get the free sample in PDF or EPUB, or read the sample online here

The Leanpub 60 Day 100% Happiness Guarantee

Within 60 days of purchase you can get a 100% refund on any Leanpub purchase, in two clicks.

See full terms...

Earn $8 on a $10 Purchase, and $16 on a $20 Purchase

We pay 80% royalties on purchases of $7.99 or more, and 80% royalties minus a 50 cent flat fee on purchases between $0.99 and $7.98. You earn $8 on a $10 sale, and $16 on a $20 sale. So, if we sell 5000 non-refunded copies of your book for $20, you'll earn $80,000.

(Yes, some authors have already earned much more than that on Leanpub.)

In fact, authors have earned over $15 million writing, publishing and selling on Leanpub.

Learn more about writing on Leanpub

Free Updates. DRM Free.

If you buy a Leanpub book, you get free updates for as long as the author updates the book! Many authors use Leanpub to publish their books in-progress, while they are writing them. All readers get free updates, regardless of when they bought the book or how much they paid (including free).

Most Leanpub books are available in PDF (for computers) and EPUB (for phones, tablets and Kindle). The formats that a book includes are shown at the top right corner of this page.

Finally, Leanpub books don't have any DRM copy-protection nonsense, so you can easily read them on any supported device.

Learn more about Leanpub's ebook formats and where to read them

Write and Publish on Leanpub

You can use Leanpub to easily write, publish and sell in-progress and completed ebooks and online courses!

Leanpub is a powerful platform for serious authors, combining a simple, elegant writing and publishing workflow with a store focused on selling in-progress ebooks.

Leanpub is a magical typewriter for authors: just write in plain text, and to publish your ebook, just click a button. (Or, if you are producing your ebook your own way, you can even upload your own PDF and/or EPUB files and then publish with one click!) It really is that easy.

Learn more about writing on Leanpub