Python NumPy Foundation
NumPy Topic 12 Foundation

Fast numbers in grids, not Python loops

NumPy stores values in contiguous arrays and applies math to whole arrays at once (vectorization).

Picture this: a fast grid of numbers

A NumPy array is a block of numbers. Math applies to every cell at once.

Python listslow loop
→
np.arraygrid
→
+ * meanall cells
→
result arraysame shape

In easy words

A NumPy array is a typed grid of numbers. Instead of writing a for-loop over each value, you call one operation and NumPy does it for every cell — faster and shorter.

Diagram — ndarray grid

1 2 3 4 5 6 a * 2 → elementwise fast numeric arrays

Where this shows up

Scientific computing, machine learning features, image pixels as arrays, finance time series, and any heavy numeric workload in Python.

Key facts

  • ndarray — Homogeneous typed grid (usually float/int).
  • Vectorization — One expression updates all elements.
  • Shape — arr.shape tells dimensions like (n,) or (rows, cols).
  • Broadcasting — Compatible shapes combine without manual tiling.

What to remember

  • Prefer arrays over lists — For numeric math at scale.
  • Same dtype — All cells share one type for speed.
  • Import style — import numpy as np is the convention.
  • Inspect first — print(arr), arr.shape, arr.dtype.
Interactive visualizer — click a cell

Array cells

Click a value to inspect index and dtype idea

Syntax reference

1import numpy as np
2arr = np.array([1, 2, 3, 4, 5])
3print(arr.shape, arr.dtype)
4print(arr * 2) # vectorized

NumPy — Topic Quiz

Check understanding

Answer all questions, then click Check answers. Use this before Practice in the editor.

Q1. NumPy’s core object is…

Q2. Elementwise means…

Q3. np.mean(a) computes…

Q4. Why use NumPy over pure Python lists for math?

Score: —