Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I get the same print format to output within julia code that I get in the julia console?

Tags:

julia

When using the julia console and you type something like this:

[10,20]*[1:100,1:100]'

You will get output like this:

2x200 Array{Int64,2}:
 10  20  30  40   50   60   70   80   90  100  …   930   940   950   960   970   980   990  1000
 20  40  60  80  100  120  140  160  180  200     1860  1880  1900  1920  1940  1960  1980  2000

How can I get this output format when executing code like this julia my_code.jl ?

Right now I am using println() and @show, but they output the full array and no information about the dimensions or type, which would be great to see. I also usually don't need to see a full 3x60,000 element matrix printed, but it would often be good to see the first and last few elements. Is there any easy way to do this (get the same output the julia console formats so nicely)?

like image 745
Chris Avatar asked Jan 06 '23 07:01

Chris


1 Answers

You could use display:

(3.5.1) dsm@notebook:~/coding$ less d.jl 
x = [10;20]*[1:100;1:100]';
display(x)
println()
(3.5.1) dsm@notebook:~/coding$ julia d.jl 
2x200 Array{Int32,2}:
 10  20  30  40   50   60   70   80   90  100  110  120  …   930   940   950   960   970   980   990  1000
 20  40  60  80  100  120  140  160  180  200  220  240     1860  1880  1900  1920  1940  1960  1980  2000

If I'm reading the source right, this ultimately delegates to writemime via TextDisplay (as discussed here).

like image 53
DSM Avatar answered Jan 18 '23 22:01

DSM