Boss lesson · Unit 01
Which axis
Reduce, reshape and normalise a batch without mixing up rows and columns
What you practise
sum/mean/argmaxalong an axis and the shape that comes out,keepdims,reshapeand-1,transpose, stacking- Normalise a batch of features end to end
Try a question from this lesson
Pick one
Two students (rows) sat three tests (columns). What does this print?
import numpy as np
s = np.array([[5, 7, 9],
[6, 8, 4]])
print(s.sum(axis=1))Hint
The shape is (2, 3). Which of those two counts is at position 1, and what is left once it is gone?
Correct answer
[21 18]
Why
axis=1 adds along the columns, collapsing them: one total per student. The axis you name is the one that disappears. axis=0 would give [11 15 13], one total per test, and no axis gives 39.
The idea
Concept cards are short on purpose. In the app they appear between questions, after you have met the idea.
Concept
The axis you name disappears
A reduction (sum, mean, max, argmax) squashes one axis away. Read it off the shape.
For a batch shaped (samples, features), axis=0 gives one number per feature and axis=1 one per sample. keepdims=True keeps the squashed axis with size 1, so the result still broadcasts against the batch.
x (4, 3)
x.sum() () one number
x.sum(axis=0) (3,)
x.sum(axis=1) (4,)
x.sum(axis=1,
keepdims=True) (4, 1)10 more exercises in the app
- 3× type the answer
- 3× multiple choice
- 2× fill the blanks
- 1× true or false
- 1× order the lines
Bitpath is an iOS app in development. Join the waitlist and you get one email when it is ready to try.