0.3Base CampPro

Shapes, indices and sums

Read ∑ and ∏ as for-loops, count free indices to know what shape comes out, check every product's shapes, and meet einsum — index notation you can execute.

40 min

After this lesson you can

  • Translate , and nested sums into loops, and back
  • Distinguish free indices from summed (dummy) indices, and predict an expression's shape from them
  • Check the shapes of a matrix expression — including a real one from the transformer paper — before trusting it
  • Predict NumPy broadcasting, and catch the silent versus bug
  • Write loops, vectorised NumPy and einsum versions of the same computation and confirm they agree

In this lesson

  1. A sum is a loop that adds
  2. Free indices and summed indices
  3. The shape rule
  4. Shape-checking a real paper
  5. Broadcasting: shapes that stretch
  6. einsum: index notation you can run
  7. In PyTorch

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.