The complete guide to numerical computing in Python
β NumPy Complete Guide
Learn arrays, vectorized operations, broadcasting, indexing, linear algebra, and performance optimization with NumPy. It is the numerical computing tool that Pandas, PyTorch, and scikit-learn are built on.
Beginner
Updated Oct 1, 2026
~3 min read
9 sections
4 code examples
Web IDE lab included
β
NumPy Web IDE
Run code in the browser with nothing to install and learn through step-by-step examples.
Learn arrays, vectorized operations, broadcasting, indexing, linear algebra, and performance optimization with NumPy. It is the numerical computing tool that Pandas, PyTorch, and scikit-learn are built on. Rather than listing concepts, this guide is organized so you can follow the content in the order you have to make decisions on a real project.
Key perspective
Backend / systems development
Before syntax, pin down the boundaries a request crosses: validation, processing, storage, and response.
To make what you read stick, it helps to capture the flow as a picture first. The two diagrams below are reference maps you can keep coming back to while learning NumPy.
Learning flow
Rendering diagramβ¦
Architecture view
Rendering diagramβ¦
What is NumPy?
When you first open NumPy, the big picture matters more than individual commands. This section starts with the problems the concepts ahead were created to solve.
NumPy is a Python library that provides high-performance multidimensional arrays and numerical operations. Its vectorized operations, faster than loops, form the foundation of data processing and model computation. Where a pure Python loop handles each value through the interpreter one by one, NumPy performs array operations implemented in C in a single pass, finishing the same calculation tens to hundreds of times faster.
Concept
Description
ndarray
A multidimensional array holding values of the same type.
vectorization
Computes on whole arrays instead of in loops.
broadcasting
Aligns arrays of different shapes by rule so they can be computed together.
Creating arrays
Here you look at Creating arrays alongside real code. Rather than copying the example as-is, read it with an eye on the inputs, the outputs, and the parts most likely to change.
Create arrays from lists, or use helpers such as zeros, ones, and arange.
Here you look at Indexing & slicing alongside real code. Rather than copying the example as-is, read it with an eye on the inputs, the outputs, and the parts most likely to change.
Access elements with square brackets as with a list, but for a multidimensional array give an index per axis, separated by commas. Passing a boolean array as the index picks out only the elements that meet the condition.
indexing.pyPYTHON
x = np.arange(12).reshape(3, 4)# array([[ 0, 1, 2, 3],# [ 4, 5, 6, 7],# [ 8, 9, 10, 11]])x[1, 2] # 6 β row 1, column 2x[:, 1] # array([1, 5, 9]) β column 1 of every rowx[0:2, 1:3] # extract a sub-array by slicing# Boolean indexing β select only the elements that meet the conditionx[x > 5] # array([6, 7, 8, 9, 10, 11])x[x % 2 == 0] = 0 # replace every even number with 0
Broadcasting
Here you look at Broadcasting alongside real code. Rather than copying the example as-is, read it with an eye on the inputs, the outputs, and the parts most likely to change.
Automatically stretches a scalar or one-dimensional array across a larger array for computation. NumPy compares the shapes of the two arrays from the trailing end and aligns only axes whose size is 1 or equal β if the rule is not met, a ValueError is raised.
Rendering diagramβ¦
PYTHON
scores = np.array([[80, 90, 70], [60, 75, 95]]) # shape (2, 3)weights = np.array([0.3, 0.3, 0.4]) # shape (3,)weighted = scores * weights # weights is treated as (1, 3) and applied to each rowprint(weighted.sum(axis=1))
Linear algebra
Here you look at Linear algebra alongside real code. Rather than copying the example as-is, read it with an eye on the inputs, the outputs, and the parts most likely to change.
Calculations such as matrix products, inverses, and norms are the core foundation of machine learning.
Performance & memory is a point where the options diverge. Using the table to compare what each approach is for and how it differs in operation makes later decisions much easier.
For the same number of elements, the memory a NumPy array uses varies widely with its precision (dtype). When float64 is not really needed, float32 is often enough, and in a pipeline that handles large arrays the difference can decide whether you run out of memory.
dtype
Size per element
Mostly used for
float64 (default)
8 bytes
Scientific computing where precision matters
float32
4 bytes
Deep learning model weights (halves the memory)
int8 / uint8
1 byte
Image pixel values (0-255)
NumPy practical design
NumPy practical design is a point where the options diverge. Using the table to compare what each approach is for and how it differs in operation makes later decisions much easier.
With NumPy, making the shape contract clear comes before turning loops into vectorized operations. Validate the input dimensions so broadcasting does not behave differently from what you intend.
Decision point
Question to ask
Practical guideline
Boundaries
Which parts of the NumPy code are most likely to change?
Separate input/output, configuration, external integrations, and the core rules.
State
Where is state created and where does it go away?
Make the owner and lifecycle of state visible in the code.
Failure
What does the caller receive on failure?
Decide the timeout, fallback, and error contract first.
NumPy operating standards
This section covers NumPy operating standards from a practical perspective. Instead of memorizing the concept, focus on the situations in which you would reach for it.
Performance is decided by contiguous memory, dtype, temporary allocations, and whether BLAS is used.
NumPy verification strategy
NumPy verification strategy is a point where the options diverge. Using the table to compare what each approach is for and how it differs in operation makes later decisions much easier.
Numeric code should include tolerance-based assertions, shape tests, and dtype tests.
Quality axis
How to verify
Definition of done
Correctness
Automate the normal/failure cases.
The core scenarios pass reproducibly.
Regression prevention
When fixing a bug, leave the same case behind as a test.
The same failure is not deployed again.
Operability
Check the logs, metrics, and alerts.
There is a path for tracing the cause when a problem occurs.
NumPy: frequently asked questions
How is a NumPy array different from a Python list?
A NumPy array stores values of one type in contiguous memory and processes operations in bulk with code implemented in C. Numeric work on large data is much faster than with lists and uses less memory. A list, on the other hand, can hold mixed types and change size freely.
What is broadcasting?
It is the rule that automatically expands the smaller array to match the larger one when arrays of different shapes are combined. Shapes are compared from the trailing dimension, and the operation works when sizes are equal or one of them is 1. It lets you add a vector to every row of a matrix without a loop, but arrays can expand to a shape you did not intend, so make a habit of checking the shape of the result.
I changed a slice of an array and the original changed too. Why?
Slicing does not copy data; it returns a view onto the original memory. To keep the original, make a copy with .copy(). Indexing with a boolean condition or an integer array, by contrast, produces a copy.