How to initialize an empty 2-dimensional array in Julia?

As of Julia 1.0 you can use:

m = Array{Float64}(undef, 0, 0)

for an (0,0)-size 2-D Matrix storing Float64 values and more in general:

m = Array{T}(undef, a, b, ...,z)

for an (a,b,...,z)-size multidimensional Matrix (whose content is garbage of type T).


Try:

m = reshape([],0,2)

or,

m = Array{Float64}(undef, 0, 2)

The second option which explicitly defines type should generate faster code.

A commenter ephemerally suggested using Matrix() for a 0x0 matrix and Matrix(0,2) for a 0x2 matrix.