Cantor's observation without words

import numpy as np import pprint pp = pprint.PrettyPrinter(indent=4) matrix_dim = 5 A = [[[j, i] for i in range(matrix_dim)] for j in range(matrix_dim)] pp.pprint(A) """ [ [[0, 0], [0, 1], [0, 2], [0, 3], [0, 4]], [[1, 0], [1, 1], [1, 2], [1, 3], [1, 4]], [[2, 0], [2, 1], [2, 2], [2, 3], [2, 4]], [[3, 0], [3, 1], [3, 2], [3, 3], [3, 4]], [[4, 0], [4, 1], [4, 2], [4, 3], [4, 4]] ] """ A = np.array(A) for i in range(matrix_dim): if i == 0: for j in range(matrix_dim): if j == 0: print(A[i, j]) else: k, l = i, j els = [A[k, l]] while l != 0: k, l = k + 1, l - 1 els.append(A[k, l]) del els[1:-1] print(np.sum(np.array(els), axis=0)) """ [0 0] [1 1] [2 2] [3 3] [4 4] """