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:
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.
Ultimately you can just write your own loop and call @printf or similar for individual elements if you want fine control over formatting. e.g.
using Printf
function myprint(io::IO, a::AbstractMatrix{<:Integer})
Base.summary(stdout, a)
rows, cols = axes(a)
for i in rows
println(io)
for j in cols
@printf(io, "%2d", a[i,j])
end
end
end
myprint(a::AbstractMatrix{<:Integer}) = myprint(stdout, a)
Yes, just the thing. I felt that if C has had printf since the early 70s, Julia must have something, and I hoped that it wouldn’t all require separate packages.
Somehow I missed Chap 85 in the language manual, putting the wrong choices into the search bar. But documentation is always confusing to a newbie, you don’t know where to drive the pitons in.
The options mentioned by other respondents will be put to use, too. Thanks to all.
Technically, printf isn’t part of the C language, you do have to add an import to use it, so it’s pretty much the same. Printf is also overkill for this particular situation.