Mistake: repeating an index sums the whole matrix
“
np.einsum('ii->', A)has no axis left over, so it must be the total.”
A = np.array([[5., 2.], [7., 3.]])
assert np.einsum("ii->", A) == 8.0
assert A.sum() == 17.0
assert np.einsum("ij->", A) == A.sum()
8.0 against 17.0. Repeating the letter selects the positions where both indices agree — the diagonal — and only then sums. Two different letters, ij->, is the sum of everything.
Which letters repeat decides what enters the sum, before any of it is added up.