Trace
The trace of a matrix is simply the sum of all value in the diagonal of the matric. Mathematically, it is represented as:
$$tr(A) = \sum_{i}^n a_{i,i}$$
Example:
$$ A = \begin{pmatrix} 2 & 1 \\ 4 & 3 \\ 3 & 2 \end{pmatrix}$$
then:
$$ tr(A) = 2 + 3 = 5 $$
Implementation in Numpy
import numpy as np
A = np.array([2,1,4,3,3,2]).reshape(3,2)
A
np.trace(A)