Bitpath

Lesson 1 · Unit 01

Arrays

Shapes, slices, masks and why loops disappear

13 exercisesabout 3 min

What you practise

  • shape, dtype, creating (zeros, arange, linspace), indexing and slicing, boolean masks, views vs copies, why vectorized beats a Python loop

Try a question from this lesson

Pick one

For a Python list, [1, 2, 3] * 2 repeats the list. What does the same line do to a NumPy array?

Python
import numpy as np

a = np.array([1, 2, 3])
print(a * 2)

The idea

Concept cards are short on purpose. In the app they appear between questions, after you have met the idea.

Concept

A grid of one type

An array is a grid of numbers that all have the same type, stored side by side in memory.

shape gives the count along each axis and dtype the kind of number. Whole-array arithmetic runs in one compiled loop, far faster than a Python for.

Python
import numpy as np

a = np.array([[1, 2, 3],
              [4, 5, 6]])
print(a.shape)   # (2, 3): rows, columns
print(a.dtype)   # int64
print(a + 10)    # every element at once

11 more exercises in the app

  • 4× type the answer
  • 2× fill the blanks
  • 3× multiple choice
  • 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