promptdojo_promptdojo_promptdojo_promptdojo_promptdojo_promptdojo_promptdojo_promptdojo_promptdojo_promptdojo_promptdojo_

Tensors and shapes before anything else — step 7 of 7

Checkpoint

One last thing before we move on. pass this to mark the lesson done, or skip and keep moving. hop to the next when you're ready.

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.