Machine learning

Stage 1 · Lesson 3 of 9

NumPy arrays, shapes and indexing

Python for data

A is a grid of numbers that all share one type, stored side by side in memory so the computer can process them quickly. Its shape tells you its size: (1000, 3) means 1,000 rows and 3 columns. Almost every ML library, from pandas to to , passes data around as arrays, so learn to read shapes fluently.

Practise creating arrays with np.array, np.zeros and np.arange. Check .shape, and .dtype for the number type. Slice out a column with a[:, 0], keep only matching values with a like a[a > 0], and change the layout with reshape.

Common trapmixing up a 1D array of shape (3,) with a 2D array of shape (3, 1) or (1, 3). They print alike but combine very differently, and shape bugs are the most common bug you will meet in the rest of this roadmap.

A question to check yourself, an AI practice session and 1 cheat sheet entry come with the full roadmap. Unlock

Resources for this stage

Start with· follow one of these

Practise

  • The Python, Pandas and Data Visualization micro courses, in browser notebooks

Keep handy

  • Start with 10 minutes to pandas, then look up indexing, groupby and reshaping

  • Quick NumPy, pandas and Matplotlib lookups with a try-it editor

Mark this stage as not done?