Your error is here:
julia> merged_stack = Array{Any}(undef, 3, 3)
3×3 Matrix{Any}:
#undef #undef #undef
#undef #undef #undef
#undef #undef #undef
julia> fill!(merged_stack, Float64[])
3×3 Matrix{Any}:
Float64[] Float64[] Float64[]
Float64[] Float64[] Float64[]
Float64[] Float64[] Float64[]
julia> append!(merged_stack[1,1],[1.0,2.0])
2-element Vector{Float64}:
1.0
2.0
julia> merged_stack
3×3 Matrix{Any}:
[1.0, 2.0] [1.0, 2.0] [1.0, 2.0]
[1.0, 2.0] [1.0, 2.0] [1.0, 2.0]
[1.0, 2.0] [1.0, 2.0] [1.0, 2.0]
The fill! fills merged_stack with the same object. Alle the empty arrays Float64[] are a single object.
There are several ways to achieve what you need, typically, I don’t have the most efficient way, but others will provide them.
You can do with a loop for example:
julia> merged_stack = Array{Vector{Float64}}(undef, 3, 3)
3×3 Matrix{Vector{Float64}}:
#undef #undef #undef
#undef #undef #undef
#undef #undef #undef
julia> for index in eachindex(merged_stack)
merged_stack[index]=Float64[]
end
julia> append!(merged_stack[1,1],[1.0,2.0])
2-element Vector{Float64}:
1.0
2.0
julia> merged_stack
3×3 Matrix{Any}:
[1.0, 2.0] Float64[] Float64[]
Float64[] Float64[] Float64[]
Float64[] Float64[] Float64[]