How can I get the sum of the elements on the secondary diagonal of a matrix? numpy.trace
seems to only return main diagonals, and numpy.diagonal
doesn't seem to help out with secondary diagonal either.
You could always just flip the array a
(top to bottom) and use np.trace
:
a[::-1].trace()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With