How to print a vector as a column vector?

In REPL, I can call

a = [1,2]

to get

2-element Vector{Int64}:
1
2

However, when I run a script and call

print(a)

, I can just get

[1, 2]

as an row vector.

Then is there a method to get a column vector as output when running a script?

All julia vectors are “column vectors”, as julia is column major. The , in [1, 2] indicates that this is a column vector. A “row vector” (which doesn’t exist in julia) would be printed like [1 2]:

julia> a = [1 2]  
1Ă—2 Matrix{Int64}:
 1  2             
                  
julia> print(a)   
[1 2]             

The real question is though, what do you want to do with that representation?

I think this thread exhausted all alternatives

When debugging, I have to print some vectors. Sometimes the entries of the vector are quite long and I think it is hard to see it visually.

try display(a) ?

2 Likes

I am sure there are many ways, but let me just suggest two (both will do the job)

  1. You could use https://github.com/ronisbr/PrettyTables.jl

or

  1. just grab the printmat.jl file from my github page https://github.com/PaulSoderlind/JuliaTutorial/tree/master/jlFiles