On formatting the display of integer arrays

rcomm
Mon, 01 Sep 2025 15:36:07 +0000
New to Julia

I do combinatorial work which generates arrays containing small integers.
Some arrays are large, so to reduce memory footprint all calculations are done in UInt8. Part of the analysis is to visually scan displays of selected areas of the arrays for numeric patterns (ie, it’s not just to check numeric correctness). Unfortunately Julia prints integer arrays in this verbose & visually indigestible format:

 0x00  0x01  0x01  0x02  0x01  0x02  0x02  0x03  0x01  0x02
 0x01  0x00  0x02  0x01  0x02  0x01  0x03  0x02  0x02  0x01
 0x01  0x02  0x00  0x01  0x02  0x03  0x01  0x02  0x02  0x03
 0x02  0x01  0x01  0x00  0x03  0x02  0x02  0x01  0x03  0x02
 0x01  0x02  0x02  0x03  0x00  0x01  0x01  0x02  0x02  0x03

What I need is this:

0 1 1 2 1 2 2 3 1 2
1 0 2 1 2 1 3 2 2 1
1 2 0 1 2 3 1 2 2 3
2 1 1 0 3 2 2 1 3 2
1 2 2 3 0 1 1 2 2 3

Converting the array to floats helps a bit - but still too cluttered:

 0.0  1.0  1.0  2.0  1.0  2.0  2.0  3.0  1.0  2.0
 1.0  0.0  2.0  1.0  2.0  1.0  3.0  2.0  2.0  1.0
 1.0  2.0  0.0  1.0  2.0  3.0  1.0  2.0  2.0  3.0
 2.0  1.0  1.0  0.0  3.0  2.0  2.0  1.0  3.0  2.0
 1.0  2.0  2.0  3.0  0.0  1.0  1.0  2.0  2.0  3.0

I can’t find display functions in base Julia that offer any further control over the display formatting. The manual doesn’t have any section on display, and only passing minor references in the text. Am I missing some key section? This is basic functionality IMO.

At a minimum I want to eliminate leading zeroes & the fractional field, and control the spacing width. Choice of the radix used for the displayed numbers would also be useful. Please tell me the simplest way to do these things in Julia.

7 posts - 6 participants