def matrix(mat):
import ROOT<EOL>if isinstance(mat, (ROOT.TMatrixD, ROOT.TMatrixDSym)):<EOL><INDENT>return _librootnumpy.matrix_d(ROOT.AsCObject(mat))<EOL><DEDENT>elif isinstance(mat, (ROOT.TMatrixF, ROOT.TMatrixFSym)):<EOL><INDENT>return _librootnumpy.matrix_f(ROOT.AsCObject(mat))<EOL><DEDENT>raise TypeError(<EOL>"<STR_LIT>"<EOL>"<STR_LIT>".format(type(mat)))<EOL>
Convert a ROOT TMatrix into a NumPy matrix.

    Parameters
    ----------
    mat : ROOT TMatrixT
        A ROOT TMatrixD or TMatrixF

    Returns
    -------
    mat : numpy.matrix
        A NumPy matrix

    Examples
    --------
    >>> from root_numpy import matrix
    >>> from ROOT import TMatrixD
    >>> a = TMatrixD(4, 4)
    >>> a[1][2] = 2
    >>> matrix(a)
    matrix([[ 0.,  0.,  0.,  0.],
            [ 0.,  0.,  2.,  0.],
            [ 0.,  0.,  0.,  0.],
            [ 0.,  0.,  0.,  0.]])