How to calculate Diagonal of a Matrix?

This recipe helps you calculate Diagonal of a Matrix
In [1]:
## How to calculate Diagonal of a Matrix
def Kickstarter_Example_8():
    print()
    print(format('How to calculate Diagonal of a Matrix', '*^72'))
    # Load library
    import numpy as np
    # Create matrix
    matrix = np.array([[1, 2, 3, 23],
                       [4, 5, 6, 25],
                       [7, 8, 9, 28],
                       [10, 11, 12, 41]])
    # Return diagonal elements
    print()
    print(matrix.diagonal())
    # Calculate the tracre of the matrix
    print()
    print(matrix.diagonal().sum())
Kickstarter_Example_8()
*****************How to calculate Diagonal of a Matrix******************

[ 1  5  9 41]

56