Project DelphiTensors Workshop

A batch axis costs one letter

gray = np.einsum('hwc,c->hw', photo, w) # (512, 512) gray_batch = np.einsum('nhwc,c->nhw', batch, w) # (2, 512, 512)

Adding a batch axis costs exactly one letter. The rule does not change, the contraction does not change, and the same expression works for one image or for a million.

This is why einsum is worth learning: it reads like the mathematics in Chapter 2, and it scales without being rewritten.