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:
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.
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
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}:
0.0
0.0
julia> size(myvector) # returns a 1-element tuple because there is only one dimension
(2,)
julia> mymatrix = fill(0.0, 2, 1) # 2x1 matrix
2Ă—1 Array{Float64,2}:
0.0
0.0
julia> size(mymatrix) # returns a 2-element tuple
(2, 1)
julia> typeof(myvector) # Array{Float64, 1}, in which 1 is the number of dimensions
Array{Float64,1}
julia> typeof(mymatrix) # Array{Float64, 2}, because it has 2 dimensions
Array{Float64,2}
julia> myvector == mymatrix # a matrix and a vector are not the same thing
false
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??)
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}:
0.0
0.0
julia> M * v
2-element Array{Float64,1}:
0.0
0.0
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.