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)
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
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]
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.
[;] 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.