wulfric.print_2d_array#

wulfric.print_2d_array(array, fmt='>.2f', highlight=False, print_result=True, borders=True, shift=0, header_row=None, footer_row=None, header_column=None, footer_column=None)[source]#

Decorates 1D and 2D arrays.

Parameters:
array(N,) or (N, M) array-like

Array to be decorated.

fmtstr, default ">.2f"

Format string.

highlightbool, default False

Whether to highlight positive and negative values. Only works for real-valued arrays.

print_resultbool, default True

Whether to print the result or return it as a string.

bordersbool, default True

Whether to print borders around the array.

shiftint, default 0

Shifts the array to the right by shift columns.

header_rowlist, optional

Header of the table (top). Has to have the same length as the number of columns. Has to had one more element for each if header_column or footer_column is not None.

footer_rowlist, optional

Footer of the table (bottom). Has to have the same length as the number of columns. Has to had one more element for each if header_column or footer_column is not None.

header_columnlist, optional

Header of the table (left). Has to have the same length as the number of rows.

footer_columnlist, optional

Footer of the table (right). Has to have the same length as the number of rows.

Returns:
stringstr

String representation of the array. Returned only if print_result is False.

Examples

>>> import wulfric as wulf
>>> array = [[1, 2], [3, 4], [5, 6]]
>>> wulf.print_2d_array(array)
┌──────┬──────┐
│ 1.00 │ 2.00 │
├──────┼──────┤
│ 3.00 │ 4.00 │
├──────┼──────┤
│ 5.00 │ 6.00 │
└──────┴──────┘
>>> wulf.print_2d_array(array, header_column=["a", "B", "c"], header_row = ["", "A", "B"])
┌───┬──────┬──────┐
│   │    A │    B │
├───┼──────┼──────┤
│ a │ 1.00 │ 2.00 │
├───┼──────┼──────┤
│ B │ 3.00 │ 4.00 │
├───┼──────┼──────┤
│ c │ 5.00 │ 6.00 │
└───┴──────┴──────┘
>>> array[1][1] = None
>>> wulf.print_2d_array(array)
┌──────┬──────┐
│ 1.00 │ 2.00 │
├──────┼──────┤
│ 3.00 │      │
├──────┼──────┤
│ 5.00 │ 6.00 │
└──────┴──────┘
>>> array = [[1, 2 + 1j], [3, 4], [52, 6]]
>>> wulf.print_2d_array(array)
┌───────┬──────────────┐
│  1.00 │ 2.00 + i1.00 │
├───────┼──────────────┤
│  3.00 │ 4.00         │
├───────┼──────────────┤
│ 52.00 │ 6.00         │
└───────┴──────────────┘