# How to create array of arrays

**URL:** <https://discourse.julialang.org/t/how-to-create-array-of-arrays/58745>\
**Category:** New to Julia\
**Tags:** question\
**Created:** [April 7, 2021, 10:53am UTC](https://discourse.julialang.org/t/how-to-create-array-of-arrays/58745 "2021-04-07T10:53:02Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![manoj.centura](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/manoj.centura/32/216443_2.png) [@manoj.centura](https://discourse.julialang.org/u/manoj.centura)\
**Post date:** [April 7, 2021, 10:53am UTC](https://discourse.julialang.org/t/how-to-create-array-of-arrays/58745/1 "2021-04-07T10:53:02Z")

</div>

How to create a array of arrays. I am trying this.

```julia
julia> a =[2,3]
2-element Array{Int64,1}:
 2
 3

julia> b=[]
0-element Array{Any,1}

julia> push!(b,a)
1-element Array{Any,1}:
 [2, 3]

julia> empty!(a)
0-element Array{Int64,1}

julia> b
1-element Array{Any,1}:
 Int64[]

```

Here the array b is empty. I want the array to be as it before deleting array a

---

<div class="post-metadata">

**Author:** ![nilshg](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nilshg/32/2283_2.png) [@nilshg](https://discourse.julialang.org/u/nilshg)\
**Post date:** [April 7, 2021, 10:56am UTC](https://discourse.julialang.org/t/how-to-create-array-of-arrays/58745/2 "2021-04-07T10:56:49Z")

</div>

Could you explain what exactly you are expecting? `b` isn’t empty in your example above:

```julia
julia> b[1]
Int64[]

```

there’s an empty array of integers in `b` (which you put there and then emptied).

---

<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:** [April 7, 2021, 10:59am UTC](https://discourse.julialang.org/t/how-to-create-array-of-arrays/58745/3 "2021-04-07T10:59:13Z")

</div>

```julia
push!(b,deepcopy(a))

```

or

```julia
push!(b,copy(a))

```

would be enough in above example case.

---

<div class="post-metadata">

**Author:** ![heliosdrm](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/heliosdrm/32/3851_2.png) [@heliosdrm](https://discourse.julialang.org/u/heliosdrm)\
**Post date:** [April 7, 2021, 12:29pm UTC](https://discourse.julialang.org/t/how-to-create-array-of-arrays/58745/4 "2021-04-07T12:29:48Z")

</div>

Recent related thread:

> [@Array assignment is alias and assignment semantics](https://discourse.julialang.org/t/array-assignment-is-alias-and-assignment-semantics/58735):
>
> Why? I started this post because I found that array assignment created an alias, leading to an unexpected problem. I wasn’t sure if this was a bug. But it’s now clear that it is the expected behavior. So my goals are to help others who may encounter this; to understand how assignment semantics work in general, and how to find out information on same; to take some probably ineffective shots at the documenation grinning. Behavior Apparently if aa is an Array and I set bb = aa then changin…

---

<div class="post-metadata">

**Author:** ![manoj.centura](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/manoj.centura/32/216443_2.png) [@manoj.centura](https://discourse.julialang.org/u/manoj.centura)\
**Post date:** [April 7, 2021, 12:39pm UTC](https://discourse.julialang.org/t/how-to-create-array-of-arrays/58745/5 "2021-04-07T12:39:43Z")

</div>

Thanks @oheil.
