How to Calculate Trace of a Matrix?

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

Calculate the tracre of the matrix:  15