arr = [[[(i + j + k) for i in range(5)] for j in range(5)] for k in range(5)]
corner1 = [0, 0, 0]
corner2 = [1, 1, 1]
print(diagonal(arr, corner1, corner2))
print([arr[i][i][i] for i in range(len(arr))])
arr2 = [[(i + j) for i in range(5)] for j in range(5)]
corner12 = [0, 1]
corner22 = [1, 1]
print(diagonal(arr2, corner12, corner22))
print([arr2[i][-1] for i in range(len(arr2))])
Get all diagonals (including minor ones) of a multi-dimensional array with numpy