larray.Array.dump

Array.dump(self, header=True, wide=True, value_name='value', light=False, axes_names=True, na_repr='as_is', maxlines=-1, edgeitems=5)[source]

Dump array as a 2D nested list. This is especially useful when writing to an Excel sheet via open_excel().

Parameters:
header : bool

Whether or not to output axes names and labels.

wide : boolean, optional

Whether or not to write arrays in “wide” format. If True, arrays are exported with the last axis represented horizontally. If False, arrays are exported in “narrow” format: one column per axis plus one value column. Not used if header=False. Defaults to True.

value_name : str, optional

Name of the column containing the values (last column) when wide=False (see above). Not used if header=False. Defaults to ‘value’.

light : bool, optional

Whether or not to hide repeated labels. In other words, only show a label if it is different from the previous one. Defaults to False.

axes_names : bool or ‘except_last’, optional

Assuming header is True, whether or not to include axes names. If axes_names is ‘except_last’, all axes names will be included except the last. Defaults to True.

na_repr : any scalar, optional

Replace missing values (NaN floats) by this value. Defaults to ‘as_is’ (do not do any replacement).

maxlines : int, optional

Maximum number of lines to show. Defaults to -1 (all lines are shown).

edgeitems : int, optional

If number of lines to display is greater than maxlines, only the first and last edgeitems lines are displayed. Only active if maxlines is not -1. Defaults to 5.

Returns:
2D nested list of builtin Python values or None for 0d arrays

Examples

>>> arr = ndtest((2, 2, 2))
>>> arr.dump()                               # doctest: +NORMALIZE_WHITESPACE
[['a',  'b\\c', 'c0', 'c1'],
 ['a0',   'b0',    0,    1],
 ['a0',   'b1',    2,    3],
 ['a1',   'b0',    4,    5],
 ['a1',   'b1',    6,    7]]
>>> arr.dump(axes_names=False)               # doctest: +NORMALIZE_WHITESPACE
[['',       '', 'c0', 'c1'],
 ['a0',   'b0',    0,    1],
 ['a0',   'b1',    2,    3],
 ['a1',   'b0',    4,    5],
 ['a1',   'b1',    6,    7]]
>>> arr.dump(axes_names='except_last')       # doctest: +NORMALIZE_WHITESPACE
[['a',     'b', 'c0', 'c1'],
 ['a0',   'b0',    0,    1],
 ['a0',   'b1',    2,    3],
 ['a1',   'b0',    4,    5],
 ['a1',   'b1',    6,    7]]
>>> arr.dump(light=True)                     # doctest: +NORMALIZE_WHITESPACE
[['a',  'b\\c', 'c0', 'c1'],
 ['a0',   'b0',    0,    1],
 ['',     'b1',    2,    3],
 ['a1',   'b0',    4,    5],
 ['',     'b1',    6,    7]]
>>> arr.dump(wide=False, value_name='data')  # doctest: +NORMALIZE_WHITESPACE
[['a',   'b',  'c', 'data'],
 ['a0', 'b0', 'c0',      0],
 ['a0', 'b0', 'c1',      1],
 ['a0', 'b1', 'c0',      2],
 ['a0', 'b1', 'c1',      3],
 ['a1', 'b0', 'c0',      4],
 ['a1', 'b0', 'c1',      5],
 ['a1', 'b1', 'c0',      6],
 ['a1', 'b1', 'c1',      7]]
>>> arr.dump(maxlines=3, edgeitems=1)        # doctest: +NORMALIZE_WHITESPACE
[['a',   'b\\c',  'c0',  'c1'],
 ['a0',    'b0',     0,     1],
 ['...',  '...', '...', '...'],
 ['a1',    'b1',     6,     7]]