'Creates a TableForm.
Parameters:
data ...
2D data to be put into the table; data can be
given as a Matrix
headings ...
gives the labels for rows and columns:
Can be a single argument that applies to both
dimensions:
- None ... no labels
- "automatic" ... labels are 1, 2, 3, ...
Can be a list of labels for rows and columns:
The lables for each dimension can be given
as None, "automatic", or [l1, l2, ...] e.g.
["automatic", None] will number the rows
[default: None]
alignments ...
alignment of the columns with:
- "left" or "<"
- "center" or "^"
- "right" or ">"
When given as a single value, the value is used for
all columns. The row headings (if given) will be
right justified unless an explicit alignment is
given for it and all other columns.
[default: "left"]
formats ...
a list of format strings or functions that accept
3 arguments (entry, row number, col number) and
return a string for the table entry. (If a function
returns None then the _print method will be used.)
wipe_zeros ...
Don\'t show zeros in the table.
[default: True]
pad ...
the string to use to indicate a missing value (e.g.
elements that are None or those that are missing
from the end of a row (i.e. any row that is shorter
than the rest is assumed to have missing values).
When None, nothing will be shown for values that
are missing from the end of a row; values that are
None, however, will be shown.
[default: None]
Examples
>>> from sympy import TableForm, Matrix
>>> TableForm([[5, 7], [4, 2], [10, 3]])
5  7
4  2
10 3
>>> TableForm([list(\'.\'*i) for i in range(1, 4)], headings=\'automatic\')
| 1 2 3
1 | .
2 | . .
3 | . . .
>>> TableForm([[\'.\'*(j if not i%2 else 1) for i in range(3)]
...            for j in range(4)], alignments=\'rcl\')'

def __init__(self, data, **kwarg):

    from sympy import Symbol, S, Matrix
    from sympy.core.sympify import SympifyError
    if isinstance(data, Matrix):
        data = data.tolist()
    _w = len(data[0])
    _h = len(data)
    pad = kwarg.get('pad', None)
    ok_None = False
    if (pad is None):
        pad = '    '
        ok_None = True
    pad = Symbol(pad)
    _w = max((len(line) for line in data))
    for (i, line) in enumerate(data):
        if (len(line) != _w):
            line.extend(([pad] * (_w - len(line))))
        for (j, lj) in enumerate(line):
            if (lj is None):
                if (not ok_None):
                    lj = pad
            else:
                try:
                    lj = S(lj)
                except SympifyError:
                    lj = Symbol(str(lj))
            line[j] = lj
        data[i] = line
    _lines = Tuple(*data)
    headings = kwarg.get('headings', [None, None])
    if (headings == 'automatic'):
        _headings = [range(1, (_h + 1)), range(1, (_w + 1))]
    else:
        (h1, h2) = headings
        if (h1 == 'automatic'):
            h1 = range(1, (_h + 1))
        if (h2 == 'automatic'):
            h2 = range(1, (_w + 1))
        _headings = [h1, h2]
    allow = ('l', 'r', 'c')
    alignments = kwarg.get('alignments', 'l')
    def _std_align(a):
        a = a.strip().lower()
        if (len(a) > 1):
            return {'left': 'l', 'right': 'r', 'center': 'c'}.get(a, a)
        else:
            return {'<': 'l', '>': 'r', '^': 'c'}.get(a, a)
    std_align = _std_align(alignments)
    if (std_align in allow):
        _alignments = ([std_align] * _w)
    else:
        _alignments = []
        for a in alignments:
            std_align = _std_align(a)
            _alignments.append(std_align)
            if (std_align not in ('l', 'r', 'c')):
                raise ValueError(('alignment    "%s"    unrecognized' % alignments))
    if (_headings[0] and (len(_alignments) == (_w + 1))):
        _head_align = _alignments[0]
        _alignments = _alignments[1:]
    else:
        _head_align = 'r'
    if (len(_alignments) != _w):
        raise ValueError(('wrong    number    of    alignments:    expected    %s    but    got    %s' % (_w, len(_alignments))))
    _column_formats = kwarg.get('formats', ([None] * _w))
    _wipe_zeros = kwarg.get('wipe_zeros', True)
    self._w = _w
    self._h = _h
    self._lines = _lines
    self._headings = _headings
    self._head_align = _head_align
    self._alignments = _alignments
    self._column_formats = _column_formats
    self._wipe_zeros = _wipe_zeros
