Given a 2D rectangular numpy array:
a = np.array([
[1, 2, 3],
[4, 5, 6],
[7, 8, 9]
])
I would like to take the sum of all values under the lower left to upper right diagonal , I.E. 8
, 9
and 6
.
What is the best way to accomplish this?
The method should work for large arrays too.