Note that `f[#1, #2, #3, #4] &` is just `f`—this substitution by itself saves some time—and that `Apply` (`@@@`) has a secret levelspec argument! You want `{2}`, i.e. `Apply[f, ATensor, {2}]`.

Note also that you've accidentally pseudo-0-indexed `ATensor` with the `{i, 0, n}` iterator. This means that you lose a row when writing  `/@ Range[n]`, since `Range[n]` is `{1, ... , n}`, and list indices are likewise 1-indexed (so you lose the last row, not the first). However, you should *never* have to map over indices like this (well, almost never); all your mapping should be doable with `Map` and `Apply` directly, both of which take levelspec args. You may also find functions like `TensorTranspose` and `ArrayReduce` (and, in that context, the operator form `Apply[f]`) helpful. Hope this helps!