Skip to content

[BUG] Printing arrays does not match standard NumPy #728

@sfe-SparkFro

Description

@sfe-SparkFro

Describe the bug

Calling print(my_array) often does not match standard NumPy output. Multi-dimensional arrays also only summarized (inserted ... when the axis is long) along one axis; all other axes get fully printed, resulting in the REPL getting flooded with numbers if a large multi-dimensional array is printed. And there is no padding to align elements, so it can be hard to see what column an element is aligned with

ulab version: 6.8.0-4D-c

To Reproduce

Some examples:

# Multi-dimensional arrays only summarize (inserted `...`) along one axis
# Also happens with 3D and 4D arrays
my_array = np.zeros((25, 50), dtype=np.uint8)
print("Example 1 - Axis summarization")
print(my_array)

# Padding is not added to align elements
my_array = np.zeros((6, 6), dtype=np.uint8)
my_array[0:3, :] = 255
my_array[2:4, 2:4] = 50
print("Example 2 - Padding")
print(my_array)

Expected behavior

Example 1 - Axis summarization
[[0 0 0 ... 0 0 0]
 [0 0 0 ... 0 0 0]
 [0 0 0 ... 0 0 0]
 ...
 [0 0 0 ... 0 0 0]
 [0 0 0 ... 0 0 0]
 [0 0 0 ... 0 0 0]]
Example 2 - Padding
[[255 255 255 255 255 255]
 [255 255 255 255 255 255]
 [255 255  50  50 255 255]
 [  0   0  50  50   0   0]
 [  0   0   0   0   0   0]
 [  0   0   0   0   0   0]]

Actual behavior

Example 1 - Axis summarization
array([[0, 0, 0, ..., 0, 0, 0],
       [0, 0, 0, ..., 0, 0, 0],
       [0, 0, 0, ..., 0, 0, 0],
       [0, 0, 0, ..., 0, 0, 0],
       [0, 0, 0, ..., 0, 0, 0],
       [0, 0, 0, ..., 0, 0, 0],
       [0, 0, 0, ..., 0, 0, 0],
       [0, 0, 0, ..., 0, 0, 0],
       [0, 0, 0, ..., 0, 0, 0],
       [0, 0, 0, ..., 0, 0, 0],
       [0, 0, 0, ..., 0, 0, 0],
       [0, 0, 0, ..., 0, 0, 0],
       [0, 0, 0, ..., 0, 0, 0],
       [0, 0, 0, ..., 0, 0, 0],
       [0, 0, 0, ..., 0, 0, 0],
       [0, 0, 0, ..., 0, 0, 0],
       [0, 0, 0, ..., 0, 0, 0],
       [0, 0, 0, ..., 0, 0, 0],
       [0, 0, 0, ..., 0, 0, 0],
       [0, 0, 0, ..., 0, 0, 0],
       [0, 0, 0, ..., 0, 0, 0],
       [0, 0, 0, ..., 0, 0, 0],
       [0, 0, 0, ..., 0, 0, 0],
       [0, 0, 0, ..., 0, 0, 0],
       [0, 0, 0, ..., 0, 0, 0]], dtype=uint8)
Example 2 - Padding
array([[255, 255, 255, 255, 255, 255],
       [255, 255, 255, 255, 255, 255],
       [255, 255, 50, 50, 255, 255],
       [0, 0, 50, 50, 0, 0],
       [0, 0, 0, 0, 0, 0],
       [0, 0, 0, 0, 0, 0]], dtype=uint8)

Additional context

There are other minor discrepancies, like ulab wrapping arrays with array(..., dtype=...) and ulab including parentheses when standard NumPy does not. Although I don't think the print output necessarily needs to be identical to standard NumPy (that would be great!), it would be a lot nicer if summarization worked along all axes, and if padding was added for alignment elements.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions