Tiny suggestion: REPL printout of 1-dim arrays as rows


the REPL prints a nice display for a 1-dimensional arrays, but it takes a lot of rows. Instead of printing 1-D arrays in one column, the REPL could save some terminal line space by print a row, more like R:

> 1:20+0.1
[1] 1.1 2.1 3.1 4.1 5.1 6.1 7.1 8.1 9.1 10.1 11.1 12.1 13.1 14.1 15.1 16.1 17.1 18.1 19.1 20.1

as noted in the title, this is a minor nuisance.


If you want, you could transpose the vector giving you a RowVector which prints the way you prefer it:

julia> ((1:20) .+ 0.1)'
1×20 RowVector{Float64,Array{Float64,1}}:
 1.1  2.1  3.1  4.1  5.1  6.1  7.1  8.1  …  14.1  15.1  16.1  17.1  18.1  19.1  20.1


I find the current format useful because I can immediately see the dimensionality of an array. A column vector is printed as a column vector and row one as a row. It makes most sense to me.

Not to mention that there are mechanisms in place to “save” as much terminal-estate as possible, so it’s a win-win.


Try showcompact.


yes, one can indeed change specific expression. but I think it is the kind of thing that would nicely make for a REPL display option. some may prefer one, some another. (thanks for having listened.
it was a tiny suggestion, anyway.) if an option is set, it could

julia> collect(1:20)
20-element Array{Int64,1}: T: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20

julia> (collect(1:20))'
1×20 Transpose{Int64,Array{Int64,1}}:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20

I am learning julia, so I am puzzled by the type displays. 20×1 and 1×20 should be column and row vectors. I am guessing that an Array is always completely identical to a column vector, by default, and it always omit “×1”* printing at the end. The word “element” is nice. But what is the Transpose in the second type display, though? Why not just 1×20 Array{Int64,1}? I don’t want to keep the developers’ time on this, though. This belongs into “usage” for beginners.


I am guessing that an Array is always completely identical to a column vector, by default, and it always omit “×1”* printing at the end

That’s a reasonable guess, but it’s not true in Julia (it’s a common misconception, especially for people coming from Matlab). A vector in Julia is truly a 1-dimensional object, and although an N-element vector and an Nx1 matrix may have the same number of elements, they are actually different types and can behave differently:

julia> myvector = fill(0.0, 2) # 2-element vector
2-element Array{Float64,1}:

julia> size(myvector) # returns a 1-element tuple because there is only one dimension

julia> mymatrix = fill(0.0, 2, 1) # 2x1 matrix
2×1 Array{Float64,2}:

julia> size(mymatrix) # returns a 2-element tuple
(2, 1)

julia> typeof(myvector) # Array{Float64, 1}, in which 1 is the number of dimensions

julia> typeof(mymatrix) # Array{Float64, 2}, because it has 2 dimensions

julia> myvector == mymatrix  # a matrix and a vector are not the same thing


thank you, robin. but then, another confused beginner question. if an array is direction-less, why should it be printed as a column vector?? now there is neither a logical reason nor good space use of the terminal. (and what is a Transpose type then??)


If you want all the gory details, you can read the discussion at https://github.com/JuliaLang/julia/issues/4774 or watch this talk from JuliaCon: https://www.youtube.com/watch?v=C2RO34b_oPM

But if you just want a simple justification, then consider that vectors behave like columns under matrix multiplication:

julia> M = zeros(2, 2)
2×2 Array{Float64,2}:
 0.0  0.0
 0.0  0.0

julia> v = zeros(2)
2-element Array{Float64,1}:

julia> M * v
2-element Array{Float64,1}:

julia> M * v'
ERROR: DimensionMismatch("A has dimensions (2,2) but B has dimensions (1,2)")


We used to do this. As a result, there was a lot of confusion about the fact that vectors printed as rows but behave like columns. We changed the printing of vectors to be vertical and the confusion went away, and it became immediately obvious to people that vectors should behave like columns, not rows.

I really wish that vectors were identified with rows instead of columns, since that would make many things much more convenient, but that ship has sailed long ago – linear algebra is firmly column-oriented. Given that, we can either live with this and match every linear algebra text ever or change it and start our own dialect of mathematics.


Some (many? old?) maths books print vectors as e.g.

(3, 4, 5)ᵀ

with the transpose symbol, to both save space and be mathematically “correct” when thinking of column vectors.


You are probably thinking of (3 4 5)ᵀ or [3 4 5]ᵀ, since row vectors are usually not comma-delimited.

IIRC, Strang’s book prints row vectors as [3 4 5] and prints column vectors inline as (3,4,5), but I find that students easily get confused by this.


I usually use print(A) when I want to see a vector compactly.


Wikipedia lists both (/ various) notations: