Arrays: NumPy and SciPy

An array is a flat block of memory plus a few numbers that say how to read it. Learn those numbers and views, broadcasting, vectorisation and SciPy stop being magic.

45 min

After this lesson you can

  • Describe an ndarray as a buffer plus dtype, shape, strides and offset, and compute the strides of any C-ordered array
  • Predict whether slicing, transposing or reshaping gives a view or a copy
  • Apply NumPy's broadcasting rule to two shapes, and explain it as a stride of zero
  • Explain why a Python loop is slow and a vectorised call is fast, and what BLAS and LAPACK do underneath
  • Use SciPy for linear algebra, optimisation (BFGS, L-BFGS-B), sparse matrices, statistics and signals

In this lesson

  1. What an array really is
  2. Views and copies
  3. Broadcasting: arithmetic between different shapes
  4. Why loops are slow and vectorised code is fast
  5. BLAS and LAPACK: the libraries underneath
  6. SciPy: the algorithms on top

This lesson is part of Descent Pro

Descent Pro unlocks every lesson on the route, from base camp to the summit. Every plan starts with a free trial.

Descent Pro

Start your free trial to keep reading

This lesson, and every other lesson on the route, is part of Descent Pro. Every plan starts with a free trial, and students with a .edu email get longer. Cancel before the trial ends and you pay nothing.