Skip to main content
Module 2 · Lesson 1 of 55/56 in the course~18 min
Module lessons (1/5)

numpy arrays

Lesson preview5 hands-on exercises readyMachine Learning: from first principles to practice · Module 2 — Toolkit: numpy, statistics and pandas

Arrays, shape and dtype, vectorisation instead of loops, reshaping and axes.

What you'll learn in this lesson

  • Create numpy arrays and read their shape and dtype.
  • Replace slow Python loops with vectorised operations.
  • Reshape data and compute statistics along an axis.

Overview

Machine learning means doing the same arithmetic on thousands of numbers. A Python list can hold numbers, but it cannot add two lists element by element ([1, 2] + [3, 4] glues them together). numpy gives you the ndarray: a block of numbers of one type that supports fast, element-wise maths with no loop.

This style, one expression applied to whole arrays, is called vectorisation. It is shorter, clearer and much faster than a loop.

Sections covered in this lesson

  1. 1The hook: why not plain lists?
  2. 2Interactive lab: ndarray axes and shape
  3. 3Quick Python list vs. NumPy ndarray reference
  4. 4Shape and dtype
  5. 5Reshaping
  6. 6Statistics along an axis
Pro Lesson · Module 2 — Toolkit: numpy, statistics and pandas

Unlock "numpy arrays" and the full Machine Learning: from first principles to practice curriculum

Arrays, shape and dtype, vectorisation instead of loops, reshaping and axes.

Unlock all 5 hands-on exercises in this lesson plus every advanced WebAssembly module with automated checks.

  • Instant access to all advanced modules in Machine Learning: from first principles to practice plus 17 more courses
  • Hands-on browser exercises with automated test suites and solutions
  • 14-day money-back guarantee processed via Paddle.com

14-day guarantee · Cancel anytimeModule 1, all 18 interactive games, and cheatsheets are always free.