'Returns the trace of a square matrix i.e. the sum of the
diagonal elements.
Examples
>>> from sympy import Matrix
>>> A = Matrix(2, 2, [1, 2, 3, 4])
>>> A.trace()
5'

def trace(self):

    if (not (self.rows == self.cols)):
        raise NonSquareMatrixError()
    return self._eval_trace()
