Print issue single column array

printing single column array in version 1.7.3 shows additional empty element:

julia> A = zeros(Int,3,1)
3×1 Matrix{Int64}:
0
0
0

julia> print(A)
[0; 0; 0;;]
julia>

I didn’t see such issue in case of multiple columns,
and in version 1.6.3 also no such issue, print(A) gives [0; 0; 0] as expected

This isn’t an empty element. It’s a change to how higher dimensional arrays are printed. (resulting from new syntax for higher dimensional arrays Julia 1.7 Highlights)

2 Likes

Thanks a lot for explanation, I understand that 2d 1-column array now can be created using
A=[1;1;1;;] (same as A=ones(Int,3,1)) .

But still one point:
if we consider 2d arrays (matrices) only, lets say with 1,2,3,… columns :
A=zeros(Int,3,1)
B=zeros(Int,3,2)
C=zeros(Int,3,3)
print function will give:
print(A) [0; 0; 0;;]
print(B) [0 0; 0 0; 0 0]
print(C) [0 0 0; 0 0 0; 0 0 0]

this extra ;; for matrix A is not consistent for me,
and it seems not necessary, since 3 element vector would be printed as [0,0,0] , no mixup with 3x1 matrix, even if written as [0;0;0] .

The “problem” here is that we have to find ways to distinguish vectors (one-dimensional thingies) with matrices (two-dimensional thingies) and your A is a two-dimensional thingy. Here’s the three variants on Julia REPL

julia> [0,0,0]
3-element Vector{Int64}:
 0
 0
 0

julia> [0;0;0]
3-element Vector{Int64}:
 0
 0
 0

julia> [0;0;0;;]
3×1 Matrix{Int64}:
 0
 0
 0

both , and ; are separators and for single elements you create vectors (see the first two cases) so ;; indicates the matrix here

2 Likes

Totally agree, for creation of matrices this ;; is big advantage.

My only point is the changed print shape,
vectors and matrices could easily distinguished by , or ;
julia> print([0;0;0])
[0, 0, 0]
julia> print([0,0,0])
[0, 0, 0]

julia> print([0;0;0;;])
[0; 0; 0;;]
julia> print([0 0;0 0;0 0])
[0 0; 0 0; 0 0]

can’t see need or advantage to have this extra ;; in printout of single column case.

You need the trailing ;;, because otherwise you cannot distinguish a length-3 Vector from a 3x1 Matrix.

But they’re not distinguished by , vs ;. [0; 0; 0] is a length-3 vector, not a matrix. You can convice yourself of this by typing it into the REPL, exactly like @kellertuer showed:

julia> [0; 0; 0]
3-element Vector{Int64}:
 0
 0
 0

Look, it’s a vector, not a matrix! I don’t see how you can argue with that. Printing a matrix like [0; 0; 0] would be misleading.

It’s a great advantage if you can take the output of print(x), paste it into the REPL or into a piece of source code, and have it re-create the object x.

So this is very much an improvement.

And perhaps one should recall the role of ; in Julia as a vertical concatenator:

julia> [0; [0, 0]]
3-element Vector{Int64}:
 0
 0
 0

I dont understand why this is necessary:
julia> [0,0,0] == [0;0;0] true
is there deeper reason, why ; does not create matrix ?

[;] denotes vertical concatenation. Two vectors u and v can be concatenated into a larger vector [u; v]. If you concatenate matrices, they turn into a larger matrix. The logical extension of this is that doing the same with scalars creates a vector.

Thanks to all for explaining, I begin to understand the problem, more beginner questions will not contribute here.
Conclusion for me is

julia> print(zeros(Int,3,1))
[0; 0; 0;;]

julia> print(zeros(Int,3,2))
[0 0; 0 0; 0 0]

is just minor cosmetic issue. Discussion regarding role of ; as vertical concatenator goes far beyond scope of this thread.