(table, title='', delim='|', centering='center', col_padding=2,
                header=True, headerchar='-')
return table_str
Print a table from a list of lists representing the rows of a table.

    Parameters
    ----------
    table : list
        list of lists, e.g. a table with 3 columns and 2 rows could be
        [ ['0,0', '0,1', '0,2'], ['1,0', '1,1', '1,2'] ]
    title : string
        Printed centered above the table
    delim : string
        character to delimit columns
    centering : {'left', 'right', 'center'}
        chooses justification for columns
    col_padding : int
        number of blank spaces to add to each column
    header : {True, False}
        Does the first entry of table contain column headers?
    headerchar : {string}
        character to separate column headers from rest of table

    Returns
    -------
    string representing table that's ready to be printed

    Notes
    -----
    The string for the table will have correctly justified columns
    with extra padding added into each column entry to ensure columns align.
    The characters to delimit the columns can be user defined.  This
    should be useful for printing convergence data from tests.


    Examples
    --------
    >>> from pyamg.util.utils import print_table
    >>> table = [ ['cos(0)', 'cos(pi/2)', 'cos(pi)'], ['0.0', '1.0', '0.0'] ]
    >>> table1 = print_table(table)                 # string to print
    >>> table2 = print_table(table, delim='||')
    >>> table3 = print_table(table, headerchar='*')
    >>> table4 = print_table(table, col_padding=6, centering='left')
Print a table from a list of lists representing the rows of a table.
Print a table from a list of lists representing the rows of a table .
def print_table(table, title='', delim='|', centering='center', col_padding=2,
                header=True, headerchar='-'):
    """Print a table from a list of lists representing the rows of a table.

    Parameters
    ----------
    table : list
        list of lists, e.g. a table with 3 columns and 2 rows could be
        [ ['0,0', '0,1', '0,2'], ['1,0', '1,1', '1,2'] ]
    title : string
        Printed centered above the table
    delim : string
        character to delimit columns
    centering : {'left', 'right', 'center'}
        chooses justification for columns
    col_padding : int
        number of blank spaces to add to each column
    header : {True, False}
        Does the first entry of table contain column headers?
    headerchar : {string}
        character to separate column headers from rest of table

    Returns
    -------
    string representing table that's ready to be printed

    Notes
    -----
    The string for the table will have correctly justified columns
    with extra padding added into each column entry to ensure columns align.
    The characters to delimit the columns can be user defined.  This
    should be useful for printing convergence data from tests.


    Examples
    --------
    >>> from pyamg.util.utils import print_table
    >>> table = [ ['cos(0)', 'cos(pi/2)', 'cos(pi)'], ['0.0', '1.0', '0.0'] ]
    >>> table1 = print_table(table)                 # string to print
    >>> table2 = print_table(table, delim='||')
    >>> table3 = print_table(table, headerchar='*')
    >>> table4 = print_table(table, col_padding=6, centering='left')

    """
    table_str = '\n'

    # sometimes, the table will be passed in as (title, table)
    if isinstance(table, tuple):
        title = table[0]
        table = table[1]

    # Calculate each column's width
    colwidths = []
    for row in table:
        # extend colwidths for row i
        for _ in range(len(row) - len(colwidths)):
            colwidths.append(-1)

        # Update colwidths if row[j] is wider than colwidth[j]
        for j, r in enumerate(row):
            if len(r) > colwidths[j]:
                colwidths[j] = len(r)

    # Factor in extra column padding
    for i, _ in enumerate(colwidths):
        colwidths[i] += col_padding

    # Total table width
    ttwidth = sum(colwidths) + len(delim)*(len(colwidths)-1)

    # Print Title
    if len(title) > 0:
        title = title.split('\n')
        for t in title:
            table_str += str.center(t, ttwidth) + '\n'
        table_str += '\n'

    # Choose centering scheme
    centering = centering.lower()
    if centering == 'center':
        centering = str.center
    if centering == 'right':
        centering = str.rjust
    if centering == 'left':
        centering = str.ljust

    if header:
        # Append Column Headers
        for elmt, elmtwidth in zip(table[0], colwidths):
            table_str += centering(str(elmt), elmtwidth) + delim
        if table[0] != []:
            table_str = table_str[:-len(delim)].rstrip() + '\n'

        # Append Header Separator
        #              Total Column Width            Total Col Delimiter Widths
        if len(headerchar) == 0:
            headerchar = ' '
        table_str += headerchar *\
            int(np.ceil(float(ttwidth)/float(len(headerchar)))) + '\n'

        table = table[1:]

    for row in table:
        for elmt, elmtwidth in zip(row, colwidths):
            table_str += centering(str(elmt), elmtwidth) + delim
        if row != []:
            table_str = table_str[:-len(delim)].rstrip() + '\n'
        else:
            table_str += '\n'

    return table_str
def print_table ( table , title = '' , delim = '|' , centering = 'center' , col_padding = 2 , header = True , headerchar = '-' ) : table_str = '\n' # sometimes, the table will be passed in as (title, table) if isinstance ( table , tuple ) : title = table [ 0 ] table = table [ 1 ] # Calculate each column's width colwidths = [ ] for row in table : # extend colwidths for row i for _ in range ( len ( row ) - len ( colwidths ) ) : colwidths . append ( - 1 ) # Update colwidths if row[j] is wider than colwidth[j] for j , r in enumerate ( row ) : if len ( r ) > colwidths [ j ] : colwidths [ j ] = len ( r ) # Factor in extra column padding for i , _ in enumerate ( colwidths ) : colwidths [ i ] += col_padding # Total table width ttwidth = sum ( colwidths ) + len ( delim ) * ( len ( colwidths ) - 1 ) # Print Title if len ( title ) > 0 : title = title . split ( '\n' ) for t in title : table_str += str . center ( t , ttwidth ) + '\n' table_str += '\n' # Choose centering scheme centering = centering . lower ( ) if centering == 'center' : centering = str . center if centering == 'right' : centering = str . rjust if centering == 'left' : centering = str . ljust if header : # Append Column Headers for elmt , elmtwidth in zip ( table [ 0 ] , colwidths ) : table_str += centering ( str ( elmt ) , elmtwidth ) + delim if table [ 0 ] != [ ] : table_str = table_str [ : - len ( delim ) ] . rstrip ( ) + '\n' # Append Header Separator #              Total Column Width            Total Col Delimiter Widths if len ( headerchar ) == 0 : headerchar = ' ' table_str += headerchar * int ( np . ceil ( float ( ttwidth ) / float ( len ( headerchar ) ) ) ) + '\n' table = table [ 1 : ] for row in table : for elmt , elmtwidth in zip ( row , colwidths ) : table_str += centering ( str ( elmt ) , elmtwidth ) + delim if row != [ ] : table_str = table_str [ : - len ( delim ) ] . rstrip ( ) + '\n' else : table_str += '\n' return table_str