Initialize an array of arrays in Julia
Sean Mackesey's answer will give you something of type Array{Array{T,N},1}
(or Array{Array{Int64,N},1}
, if you put the type in front of []
). If you instead want something more strongly typed, for example a vector of vectors of Int (i.e. Array{Array{Int64,1},1}
), use the following:
a = Vector{Int}[ [1,2], [3,4] ]
If you want an array of arrays as opposed to a matrix (i.e. 2-dimensional Array
):
a = Array[ [1,2], [3,4] ]
You can parameterize (specify the type of the elements) an Array
literal by putting the type in front of the []
. So here we are parameterizing the Array
literal with the Array
type. This changes the interpretation of brackets inside the literal declaration.