Bitpath

Boss lesson · Unit 01

Which axis

Reduce, reshape and normalise a batch without mixing up rows and columns

12 exercisesabout 3 min

What you practise

  • sum/mean/argmax along an axis and the shape that comes out, keepdims, reshape and -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?

Python
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?

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.

One email when Bitpath is ready to try. Nothing else. Privacy