← Learning Hub
Beginner

NumPy Arrays

A NumPy array is like a Python list of numbers, but much faster, and maths works on the whole array at once - no loop needed.

NumPy arrays do maths on whole columns of numbers at once, written in fast compiled code. That's why a calculation over a million numbers takes milliseconds. pandas is built on NumPy, so these ideas carry straight over.

Example
You can edit this code.

Filtering with conditions

Example
You can edit this code.

2-D arrays

Example
You can edit this code.

Handy functions

Example
You can edit this code.
axis=0 means "go down the rows" (one answer per column); axis=1 means "go across the columns" (one answer per row).
Key points
  • Maths on an array applies to every element.
  • Boolean masks filter arrays.
  • axis=0 goes down rows; axis=1 across columns.

📝 Test yourself

1. What does prices * 2 do on a NumPy array?
2. What does marks[marks > 60] give?
3. Fill in the attribute that gives an array's size as (rows, columns):
sales.