Strange re-typing of arrays of numbers

[] is a Vector{Any}, and literal array construction defaults to promoting all elements to the same type. Compare:

julia> x = [[2,3,4], [2,5], []]
3-element Array{Array{Any,1},1}:
 [2, 3, 4]
 [2, 5]
 []

julia> x = [[2,3,4], [2,5], Int[]]
3-element Array{Array{Int64,1},1}:
 [2, 3, 4]
 [2, 5]
 []

I think the latter is what you want.

If you really need the elements of the array to have different types, you need to declare the container to have an abstract type like Any:

julia> x = Any[[2,3,4], [2,5], []]
3-element Array{Any,1}:
 [2, 3, 4]
 [2, 5]
 Any[]

julia> x[1]
3-element Array{Int64,1}:
 2
 3
 4
3 Likes