# Multidimensional Arrays Initialization and Assignments

**URL:** <https://discourse.julialang.org/t/multidimensional-arrays-initialization-and-assignments/19682>\
**Category:** New to Julia\
**Tags:** array\
**Created:** [January 16, 2019, 4:16am UTC](https://discourse.julialang.org/t/multidimensional-arrays-initialization-and-assignments/19682 "2019-01-16T04:16:43Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![afas](https://avatars.discourse-cdn.com/v4/letter/a/8dc957/32.png) [@afas](https://discourse.julialang.org/u/afas)\
**Post date:** [January 16, 2019, 4:16am UTC](https://discourse.julialang.org/t/multidimensional-arrays-initialization-and-assignments/19682/1 "2019-01-16T04:16:43Z")

</div>

I am trying to create empty multidimensional arrays where each element of the array is a 2d Float64 array with variable numbers of elements.  
I am finding this very counter-intuitive and I am still extremely confused with how Julia deals with this easy task. I read the manual and documentation a few times and could not find a simple, clear answer for this.

I tried several different ways found here and there on the Internet and none of them worked.

`A = [Float64[] for i = 1:2 for j = 1:4]`

correctly creates a 2 by 4 empty array where every element is a 1-d Float64 array. Since I need 2d arrays I tried the following:

`A = [Array{Float64,2}[] for i=1:2 for j=1:4]`

which results in the unexpected (for me) behavior of creating an array containing Array{Array{Float64,2},1} type of elements. Again not what I was looking for.  
I understand this should be trivial but apparently it is not, at least for me.

---

<div class="post-metadata">

**Author:** ![stevengj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevengj/32/71_2.png) [@stevengj](https://discourse.julialang.org/u/stevengj)\
**Post date:** [January 16, 2019, 4:22am UTC](https://discourse.julialang.org/t/multidimensional-arrays-initialization-and-assignments/19682/2 "2019-01-16T04:22:48Z")

</div>

> [@afas](#):
>
> I am trying to create empty multidimensional arrays where each element of the array is a 2d Float64 array with variable numbers of elements.

You can do `A = [Array{Float64}(undef,0,0) for i=1:2, j=1:4]` to create a 2×4 array where every element is an empty 2d array, for example.

---

<div class="post-metadata">

**Author:** ![afas](https://avatars.discourse-cdn.com/v4/letter/a/8dc957/32.png) [@afas](https://discourse.julialang.org/u/afas)\
**Post date:** [January 16, 2019, 4:26am UTC](https://discourse.julialang.org/t/multidimensional-arrays-initialization-and-assignments/19682/3 "2019-01-16T04:26:46Z")

</div>

Thank you. This seems to be exactly what I need. Can you please explain why is this different than calling:

`A = [Array{Float64,2}[] for i=1:2 for j=1:4]`

This is extremely counter-intuitive for me.

---

<div class="post-metadata">

**Author:** ![rdeits](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rdeits/32/286_2.png) [@rdeits](https://discourse.julialang.org/u/rdeits)\
**Post date:** [January 16, 2019, 4:37am UTC](https://discourse.julialang.org/t/multidimensional-arrays-initialization-and-assignments/19682/4 "2019-01-16T04:37:23Z")

</div>

The syntax `T[]` creates an `Array{T, 1}`, that’s all.

For example: `Float64[]` creates an `Array{Float64, 1}`. By analogy, `Array{Float64, 2}[]` creates an `Array{Array{Float64, 2}, 1}`,
