The following is how I usually construct an array. Each element of array temp is an array that has different number of elements (which I assign later).
temp = Array{Array{Float64},1}(undef,10)
for ii in 1:10
temp[ii] = Float64[]
end
Is there any way to reduce this code into one line? for example, by replacing undef operator by Float64[], or anything like that?
This fills the array with 10 references to the same empty array, which probably isn’t what you want. There’s a warning in the docstring about this I believe.
Float64[] is an alias for Array{Float64,1}(). So you can use Array{Float64,2}(undef,r,c). It is necessary to specify undef and the dimensions for arrays with more than one dimension. Depending on your use case it might be simpler to use x = [fill(0.0,2,2) for i in 1:10]