def mattrans(mat):
    """
        Returns the transpose of an mxn matrix (list of lists)
    
        Arg:
            mat - A list/list of lists representing a vector/matrix (see 'matmul')
    
        Returns:
            mat_T - A transpose of shape n x m where mat has shape m x n. If mat has
                    shape (m,) we simply return mat where each element is the 
                    transpose of its corresponding element in mat.
    """
    
    if all([not isinstance(e,list) for e in mat]): # (m,) case
        return [e.T.doit() for e in mat]
    else: # Other case
        if any([not isinstance(e,list) for e in mat]):
            raise Exception("mat is not a regular matrix")
        m_T = len(mat[0])
        n_T = len(mat)
        mat_T = [[mat[j][i].T.doit() for j in range(n_T)] for i in range(m_T)]  
        return mat_T