# How can I fill an array with empty 2D arrays?

**URL:** <https://discourse.julialang.org/t/how-can-i-fill-an-array-with-empty-2d-arrays/60895>\
**Category:** New to Julia\
**Created:** [May 10, 2021, 3:02pm UTC](https://discourse.julialang.org/t/how-can-i-fill-an-array-with-empty-2d-arrays/60895 "2021-05-10T15:02:59Z")\
**Posts on this page:** 1\
**Showing post:** 5

<div class="post-metadata">

**Author:** ![BioTurboNick](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bioturbonick/32/6380_2.png) [@BioTurboNick](https://discourse.julialang.org/u/BioTurboNick)\
**Post date:** [May 10, 2021, 3:45pm UTC](https://discourse.julialang.org/t/how-can-i-fill-an-array-with-empty-2d-arrays/60895/5 "2021-05-10T15:45:00Z")

</div>

If you’re replacing the entire array that’s fine, but if you intend to predefine and then fill them, it’s still a problem:

```julia
x = fill(Matrix{Float64}(undef,2,2), 3);

julia> x
3-element Vector{Matrix{Float64}}:
 [2.75859452845e-313 3.3951932658e-313; 2.33419537065e-313 6.94677762088306e-310]
 [2.75859452845e-313 3.3951932658e-313; 2.33419537065e-313 6.94677762088306e-310]
 [2.75859452845e-313 3.3951932658e-313; 2.33419537065e-313 6.94677762088306e-310]

julia> x[1][1,1] = 5
5

julia> x
3-element Vector{Matrix{Float64}}:
 [5.0 3.3951932658e-313; 2.33419537065e-313 6.94677762088306e-310]
 [5.0 3.3951932658e-313; 2.33419537065e-313 6.94677762088306e-310]
 [5.0 3.3951932658e-313; 2.33419537065e-313 6.94677762088306e-310]

```

---

_[View the full topic](https://discourse.julialang.org/t/how-can-i-fill-an-array-with-empty-2d-arrays/60895)._
