#NEWLINE# def trace( matlist , K ) : #NEWLINE# #INDENT# '\n    Returns the trace of a matrix.\n\n    Examples\n    ========\n\n    >>> from sympy.matrices.densetools import trace, eye\n    >>> from sympy import ZZ\n    >>> a = [\n    ... [ZZ(3), ZZ(7), ZZ(4)],\n    ... [ZZ(2), ZZ(4), ZZ(5)],\n    ... [ZZ(6), ZZ(2), ZZ(3)]]\n    >>> b = eye(4, ZZ)\n    >>> trace(a, ZZ)\n    10\n    >>> trace(b, ZZ)\n    4\n\n    ' #NEWLINE# result = K . zero #NEWLINE# for i in range ( len ( matlist ) ) : #NEWLINE# #INDENT# result += matlist [ i ] [ i ] #NEWLINE# #UNINDENT# return result