One can initialize a Julia array by hand, using the square-brackets syntax:
julia> x = [1, 2, 3] 3-element Array{Int64,1}: 1 2 3
The first line after the command shows the size of the array you created. It also shows the type of its elements and its dimensionality (int this case Int64
and 1
, repectively). For a two-dimensional array, you can use spaces and semi-colon:
julia> x = [1 2 3; 4 5 6] 2x3 Array{Int64,2}: 1 2 3 4 5 6
To create an uninitialized array, you can use the Array(type, dims...)
method:
julia> Array(Int64, 3, 3) 3x3 Array{Int64,2}: 0 0 0 0 0 0 0 0 0
The functions zeros
, ones
, trues
, falses
have methods that behave exactly the same way, but produce arrays full of 0.0
, 1.0
, True
or False
, respectively.