I have a rectangular (can\'t be assumed to be square) Pandas DataFrame of numbers. Say I pick a diagonal direction (either \"upperleft to lowerright\" or \"upperright to lowerl
For a 2D numpy array A this might be (?) the shortest code to sum diagonals:
A
np.bincount(sum(np.indices(A.shape)).flat, A.flat)
To sum the opposite diagonals, you can np.fliplr the array.
np.fliplr