diff options
author | Travis Oliphant <oliphant@enthought.com> | 2006-09-27 23:20:24 +0000 |
---|---|---|
committer | Travis Oliphant <oliphant@enthought.com> | 2006-09-27 23:20:24 +0000 |
commit | 38124a012c043fb2ddc3d2eab90af4c35db619c6 (patch) | |
tree | 881ec219241b9b349b16ce376e4f675f4d154fb2 /numpy/core/arrayprint.py | |
parent | 74b68e37a478ca5d6e515196af1108e9494a01f1 (diff) | |
download | numpy-38124a012c043fb2ddc3d2eab90af4c35db619c6.tar.gz |
Fix printing of arrays with records so that nested arrays print as lists instead of using array syntax
Diffstat (limited to 'numpy/core/arrayprint.py')
-rw-r--r-- | numpy/core/arrayprint.py | 19 |
1 files changed, 18 insertions, 1 deletions
diff --git a/numpy/core/arrayprint.py b/numpy/core/arrayprint.py index 50ae4fb26..42ec4cadb 100644 --- a/numpy/core/arrayprint.py +++ b/numpy/core/arrayprint.py @@ -187,6 +187,17 @@ def _array2string(a, max_line_width, precision, suppress_small, separator=' ', return lst +def _convert_arrays(obj): + newtup = [] + for k in obj: + if isinstance(k, _gen.ndarray): + k = k.tolist() + elif isinstance(k, tuple): + k = _convert_arrays(k) + newtup.append(k) + return tuple(newtup) + + def array2string(a, max_line_width = None, precision = None, suppress_small = None, separator=' ', prefix="", style=repr): @@ -196,6 +207,8 @@ def array2string(a, max_line_width = None, precision = None, try: lst = a._format(x) except AttributeError: + if isinstance(x, tuple): + x = _convert_arrays(x) lst = style(x) elif reduce(product, a.shape) == 0: # treat as a null array if any of shape elements == 0 @@ -212,6 +225,7 @@ def _extendLine(s, line, word, max_line_len, next_line_prefix): line += word return s, line + def _formatArray(a, format_function, rank, max_line_len, next_line_prefix, separator, edge_items, summary_insert): """formatArray is designed for two modes of operation: @@ -222,7 +236,10 @@ def _formatArray(a, format_function, rank, max_line_len, """ if rank == 0: - return str(a.item()) + obj = a.item() + if isinstance(obj, tuple): + obj = _convert_arrays(obj) + return str(obj) if summary_insert and 2*edge_items < len(a): leading_items, trailing_items, summary_insert1 = \ |