SkyAICampus
HomePracticeLearnCode LabFocus

Learn

HomePracticeConcept cardsCode LabSky Tutor

Review

Revise todayMistake notebookProgress

Focus

Campus ForestFocus roomsSquads

Questions or feedback?
support@skyaicampus.com

SkyAICampus
PrivacyTermssupport@skyaicampus.com© 2026 SkyAI Campus
← All modules

NumPy

One 60-second card per skill, in learning order. 9 of 9 cards ready.

Array basics 3/3Maths on arrays 3/3Reshaping and filtering 3/3

In this module

1Array basics3 of 3 cards2Maths on arrays3 of 3 cards3Reshaping and filtering3 of 3 cards

Topic 1

Array basics

Creating arrays · Shape and data type · Indexing and slicing

▶Open the lessonPractise this topic

60-second card

Creating arrays

A NumPy array is a grid of numbers of one type, built for fast maths.

  • np.array([1, 2, 3]) turns a list into an array.
  • np.zeros(3), np.ones((2, 3)) and np.arange(0, 10, 2) make arrays quickly.
  • np.linspace(0, 1, 5) gives 5 evenly spaced numbers.
import numpy as np
print(np.arange(0, 10, 2).tolist(), np.zeros(3).tolist())

Prints

[0, 2, 4, 6, 8] [0.0, 0.0, 0.0]

Remember: import numpy as np, then build arrays with np.something().

Common mistake: Expecting np.arange(0, 10, 2) to include 10. Like range, it stops before the end.

60-second card

Shape and data type

shape tells you the size of each dimension; dtype tells you the type of every value.

  • A 2×3 array has shape (2, 3): 2 rows, 3 columns.
  • ndim is the number of dimensions; size is the total count of values.
  • Mixing ints and floats makes everything float.
import numpy as np
a = np.array([[1, 2, 3], [4, 5, 6]])
print(a.shape, a.ndim, a.size, a.dtype)

Prints

(2, 3) 2 6 int64

Remember: Check .shape whenever something looks wrong.

Common mistake: Reading shape (2, 3) as 2 columns. It's always rows first.

60-second card

Indexing and slicing

Pick values with [row, column], and ranges with start:stop.

  • a[0, 2] is row 0, column 2.
  • a[:, 1] is every row of column 1.
  • a[1:3] takes positions 1 and 2; the stop is left out.
import numpy as np
a = np.array([[1, 2, 3], [4, 5, 6]])
print(a[0, 2], a[:, 1].tolist(), a[1, 1:].tolist())

Prints

3 [2, 5] [5, 6]

Remember: Rows first, then columns, separated by a comma.

Common mistake: Changing a slice and being surprised the original changed. Slices share data; use .copy().

Topic 2

Maths on arrays

Maths on whole arrays · Sum, mean, max and more · Broadcasting

▶Open the lessonPractise this topic

60-second card

Maths on whole arrays

Maths on an array works on every value at once, with no loop needed.

  • a * 2 doubles every value.
  • a + b adds matching positions of two arrays of the same shape.
  • np.sqrt(a) and np.round(a, 1) work on every value too.
import numpy as np
a = np.array([1, 2, 3])
b = np.array([10, 20, 30])
print((a * 2).tolist(), (a + b).tolist(), int(a @ b))

Prints

[2, 4, 6] [11, 22, 33] 140

Remember: No for loops: let NumPy do the whole array.

Common mistake: Expecting a * b to be matrix multiplication. It multiplies position by position; use @ for matrices.

60-second card

Sum, mean, max and more

Aggregations squash an array into one number, or one number per row or column.

  • sum(), mean(), max(), min() and std() are built in.
  • axis=0 works down each column; axis=1 works across each row.
  • argmax() gives the position of the largest value.
import numpy as np
a = np.array([[1, 2], [3, 4]])
print(a.sum(), a.sum(axis=0).tolist(), a.sum(axis=1).tolist())

Prints

10 [4, 6] [3, 7]

Remember: axis=0 → one result per column. axis=1 → one per row.

Common mistake: Mixing up the axes. Think: axis=0 collapses the rows.

60-second card

Broadcasting

Broadcasting lets NumPy combine arrays of different shapes by stretching the smaller one.

  • A single number is stretched to every position: a + 1.
  • A row of shape (3,) is added to each row of a (2, 3) array.
  • Shapes must match from the right, or be 1.
import numpy as np
a = np.array([[1, 2, 3], [4, 5, 6]])
print((a + np.array([10, 20, 30])).tolist())

Prints

[[11, 22, 33], [14, 25, 36]]

Remember: Line the shapes up from the right; each pair must be equal or 1.

Common mistake: Adding shapes (2, 3) and (2,). Their right ends (3 and 2) don't match, so it fails.

Topic 3

Reshaping and filtering

Reshaping · Filtering with conditions · Joining arrays

▶Open the lessonPractise this topic

60-second card

Reshaping

reshape changes an array's shape without changing its values.

  • np.arange(6).reshape(2, 3) makes 2 rows of 3.
  • Use -1 to let NumPy work out one size: reshape(3, -1).
  • flatten() or ravel() turns it back into one row.
import numpy as np
a = np.arange(6).reshape(3, -1)
print(a.shape, a.tolist())

Prints

(3, 2) [[0, 1], [2, 3], [4, 5]]

Remember: The total number of values must stay the same.

Common mistake: Reshaping 6 values into (4, 2). 4 × 2 = 8, so it fails.

60-second card

Filtering with conditions

A condition on an array gives True/False for each value. Use it to pick only the matching values.

  • a > 50 gives a mask like [False, True, True].
  • a[a > 50] keeps the values where the mask is True.
  • Combine with & (and) and | (or), with brackets: (a > 50) & (a < 90).
import numpy as np
marks = np.array([45, 72, 88, 91, 60])
print(marks[(marks > 50) & (marks < 90)].tolist())

Prints

[72, 88, 60]

Remember: Use & and |, not 'and' and 'or', with arrays.

Common mistake: Leaving out the brackets: a > 50 & a < 90 runs & first and goes wrong.

60-second card

Joining arrays

Join arrays end to end with concatenate, or stack them as rows or columns.

  • np.concatenate([a, b]) joins along an existing axis.
  • np.vstack stacks as rows; np.hstack joins side by side.
  • The other dimensions must match.
import numpy as np
a = np.array([1, 2])
b = np.array([3, 4])
print(np.concatenate([a, b]).tolist(), np.vstack([a, b]).tolist())

Prints

[1, 2, 3, 4] [[1, 2], [3, 4]]

Remember: vstack = on top. hstack = side by side.

Common mistake: Stacking arrays whose other dimension differs, like rows of length 3 and 4.

Log inSign up

Practise a little every day

Five questions a day keep your Sunrise Streak going. Your progress is saved when you sign up.

Sign up free