The trace of a matrix is defined as the *sum of the elements* on the *main diagonal* of a square matrix. This concept applies only to square matrices, where the number of rows equals the number of columns.
For a square matrix $A$ with shape $(n \times n)$, the trace is given by:
$ \text{tr}(A)= \sum_{i=1}^n a_{ii} $
where $a_{ii}$ are the diagonal elements of the matrix.