Efficiently remove diagonal from Array

OK OK OK, I swear! Last one, best for last:

i = CartesianIndices(a)
k = filter(x -> x.I[1] ≠ x.I[2], i)
b = reshape(a'[k], n - 1, n)'

(I must come across as a total lunatic, I’m not, ask others here)

4 Likes