# Concatenate each

**URL:** <https://discourse.julialang.org/t/concatenate-each/70369>\
**Category:** General Usage\
**Tags:** arrays\
**Created:** [October 26, 2021, 3:00am UTC](https://discourse.julialang.org/t/concatenate-each/70369 "2021-10-26T03:00:41Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![jzr](https://avatars.discourse-cdn.com/v4/letter/j/eb9ed0/32.png) [@jzr](https://discourse.julialang.org/u/jzr)\
**Post date:** [October 26, 2021, 3:00am UTC](https://discourse.julialang.org/t/concatenate-each/70369/1 "2021-10-26T03:00:41Z")

</div>

Given `[[0,0,0],[1,1,1]]` and `[[4,5,6],[7,8,9],[10,11,12]]`, how can I get

```julia
[
  [[0,0,0],[4,5,6],[7,8,9],[10,11,12]], 
  [[1,1,1],[4,5,6],[7,8,9],[10,11,12]],
]

```

Not quite right:

```julia
julia> vcat.(([[0,0,0],[1,1,1]]), Ref([[4,5,6],[7,8,9],[10,11,12]]))
2-element Vector{Vector{Any}}:
 [0, 0, 0, [4, 5, 6], [7, 8, 9], [10, 11, 12]]
 [1, 1, 1, [4, 5, 6], [7, 8, 9], [10, 11, 12]]

```

---

<div class="post-metadata">

**Author:** ![aramirezreyes](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/aramirezreyes/32/42573_2.png) [@aramirezreyes](https://discourse.julialang.org/u/aramirezreyes)\
**Post date:** [October 26, 2021, 3:40am UTC](https://discourse.julialang.org/t/concatenate-each/70369/2 "2021-10-26T03:40:31Z")

</div>

Could be:

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

julia> b
3-element Vector{Vector{Int64}}:
 [4, 5, 6]
 [7, 8, 9]
 [10, 11, 12]

julia> [[ai, b...] for ai in a]
2-element Vector{Vector{Vector{Int64}}}:
 [[0, 0, 0], [4, 5, 6], [7, 8, 9], [10, 11, 12]]
 [[1, 1, 1], [4, 5, 6], [7, 8, 9], [10, 11, 12]]

```

Trying with other methods I think you are looking for push! instead of vcat.

---

<div class="post-metadata">

**Author:** ![Oystein\_Rognes\_Solhe](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/oystein_rognes_solhe/32/8182_2.png) [@Oystein\_Rognes\_Solhe](https://discourse.julialang.org/u/Oystein_Rognes_Solhe)\
**Post date:** [October 26, 2021, 5:19am UTC](https://discourse.julialang.org/t/concatenate-each/70369/3 "2021-10-26T05:19:20Z")

</div>

> [@aramirezreyes](#):
>
> `[[ai, b...] for ai in a]`

A different but faster approach could be

```julia
begin
    cat_a = Vector{Vector{Vector{Int}}}(undef, length(a))
    for i in eachindex(a)
        cat_a[i] = vcat([a[i]], b)
    end
    cat_a
end

```

---

<div class="post-metadata">

**Author:** ![GunnarFarneback](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gunnarfarneback/32/1827_2.png) [@GunnarFarneback](https://discourse.julialang.org/u/GunnarFarneback)\
**Post date:** [October 26, 2021, 6:11am UTC](https://discourse.julialang.org/t/concatenate-each/70369/4 "2021-10-26T06:11:11Z")

</div>

Your attempt can be fixed with an unexported function:

```julia
julia> vcat.(Base.vect.([[0,0,0],[1,1,1]]), Ref([[4,5,6],[7,8,9],[10,11,12]]))
2-element Vector{Vector{Vector{Int64}}}:
 [[0, 0, 0], [4, 5, 6], [7, 8, 9], [10, 11, 12]]
 [[1, 1, 1], [4, 5, 6], [7, 8, 9], [10, 11, 12]]

```

---

<div class="post-metadata">

**Author:** ![DNF](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dnf/32/10191_2.png) [@DNF](https://discourse.julialang.org/u/DNF)\
**Post date:** [October 26, 2021, 6:25am UTC](https://discourse.julialang.org/t/concatenate-each/70369/5 "2021-10-26T06:25:49Z")

</div>

> [@jzr](#):
>
> ```julia
> [
> [[0,0,0],[4,5,6],[7,8,9],[10,11,12]], 
> [[1,1,1],[4,5,6],[7,8,9],[10,11,12]],
> ]
> 
> ```

This looks like numpy array syntax, which is very different from Julia array syntax. Do you really mean for these to be vectors of vectors of vectors? Or are trying to create 3D arrays?
