promptdojo_

Tensors and shapes before anything else — step 7 of 7

Checkpoint

One last thing before we move on. Same surface as a write step — but the lesson doesn't complete until this passes.

Implement mean(t, dim) for a 2-D list tensor: dim=0 collapses the batch (one mean per feature, via transposing with zip(*t)), dim=1 collapses features (one mean per row); any other dim raises ValueError. Print both results in the format "dim=0: [...] -> shape (2,)" / "dim=1: [...] -> shape (3,)", then "collapsed axis differs:" with whether the output lengths differ.

full-screen editor opens — close anytime to keep reading.