# Preallocating array of matrices

**URL:** <https://discourse.julialang.org/t/preallocating-array-of-matrices/38665>\
**Category:** New to Julia\
**Tags:** question\
**Created:** [May 3, 2020, 11:46am UTC](https://discourse.julialang.org/t/preallocating-array-of-matrices/38665 "2020-05-03T11:46:14Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![oheil](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/oheil/32/220745_2.png) [@oheil](https://discourse.julialang.org/u/oheil)\
**Post date:** [May 3, 2020, 12:03pm UTC](https://discourse.julialang.org/t/preallocating-array-of-matrices/38665/2 "2020-05-03T12:03:26Z")

</div>

It’s the same like in  
[https://discourse.julialang.org/t/how-to-create-an-array-of-preallocated-mutable-structs](https://discourse.julialang.org/t/how-to-create-an-array-of-preallocated-mutable-structs)  
/18482

So:

```julia
julia> n=10
10

julia> a = [Array{Float64,2}(undef,3,3) for i in 1:n]
10-element Array{Array{Float64,2},1}:
 [8.00472116e-316 1.613449943e-315 1.04815513e-315; 1.866005866e-315 1.85975376e-315 8.0408006e-316; 1.866006024e-315 1.61345105e-315 8.00472116e-316]
 [8.0055939e-316 1.613454053e-315 1.61345453e-315; 8.0055939e-316 1.61345421e-315 1.613454686e-315; 1.166857286e-315 1.61345437e-315 1.748721164e-315]
 [1.166857286e-315 8.00472116e-316 1.748721875e-315; 8.00472116e-316 1.61345453e-315 0.0; 1.61345421e-315 1.613454686e-315 0.0]
 [1.866006024e-315 1.61345105e-315 8.00472116e-316; 1.613449943e-315 1.04815513e-315 0.0; 1.85975376e-315 8.0408006e-316 0.0]
 [1.5e-323 5.0e-324 0.0; 5.0e-324 5.0e-324 0.0; 5.0e-324 5.0e-324 0.0]
 [8.0055939e-316 6.9226573e-316 6.9226668e-316; 8.0055939e-316 6.9226605e-316 6.92266997e-316; 6.92265416e-316 6.92266364e-316 6.92267313e-316]
 [1.166857286e-315 0.0 0.0; 1.613454686e-315 0.0 0.0; 1.74872662e-315 0.0 0.0]
 [1.866006024e-315 0.0 0.0; 8.0408006e-316 0.0 0.0; 8.00472116e-316 0.0 0.0]
 [5.0e-324 0.0 0.0; 5.0e-324 0.0 0.0; 0.0 0.0 0.0]
 [6.92265416e-316 1.748716974e-315 1.748717053e-315; 8.0055939e-316 8.0055939e-316 6.9226573e-316; 8.0055939e-316 8.0055939e-316 6.9226605e-316]

```

Note: I have written `Matrix{Float64}` as `Array{Float64,2}`

Depending on what you are doing it could bring some performance advantages.

---

_[View the full topic](https://discourse.julialang.org/t/preallocating-array-of-matrices/38665)._
