How to print/show an matrix in matrix format?

Viewed 107

I would like to print an 2d array or matrix like A=[1 1;2 2;3 3] in matrix format, but when I do println(A), it prints in the format [1 1;2 2;3 3]. Is there any function or macro like @show that can print arrays in matrix format such the picture I have attached?

enter image description here

1 Answers

Yes. The Jupyter output (like the one in your screenshot) and the REPL output in the command-line both use the display function.

display(x) means "show x in the best way you can for the current output device(s)."

- from @doc(display).

julia> display(A)
3×2 Matrix{Int64}:
 1  1
 2  2
 3  3

This is automatically done for any value that occurs as the last expression in a cell (in Jupyter), but you can also explicitly call it like above if you want to show the matrix output from somewhere in the middle of the cell.

Related