# Flattening a vector of vectors

**URL:** <https://discourse.julialang.org/t/flattening-a-vector-of-vectors/91463>\
**Category:** New to Julia\
**Created:** [December 9, 2022, 10:04am UTC](https://discourse.julialang.org/t/flattening-a-vector-of-vectors/91463 "2022-12-09T10:04:11Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Nash](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nash/32/14482_2.png) [@Nash](https://discourse.julialang.org/u/Nash)\
**Post date:** [December 9, 2022, 10:04am UTC](https://discourse.julialang.org/t/flattening-a-vector-of-vectors/91463/1 "2022-12-09T10:04:11Z")

</div>

What command will let me flatten a vector of vectors?

I believe the package “Iterations” had this “flatten” command, but it appears to be deprecated.

---

<div class="post-metadata">

**Author:** ![pfitzseb](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pfitzseb/32/45566_2.png) [@pfitzseb](https://discourse.julialang.org/u/pfitzseb)\
**Post date:** [December 9, 2022, 10:09am UTC](https://discourse.julialang.org/t/flattening-a-vector-of-vectors/91463/2 "2022-12-09T10:09:48Z")

</div>

`Iterators.flatten` still works fine:

```julia
julia> Iterators.flatten([[1,2], [3,4]])
Base.Iterators.Flatten{Vector{Vector{Int64}}}([[1, 2], [3, 4]])

julia> collect(Iterators.flatten([[1,2], [3,4]]))
4-element Vector{Int64}:
 1
 2
 3
 4

```

---

<div class="post-metadata">

**Author:** ![bkamins](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bkamins/32/208538_2.png) [@bkamins](https://discourse.julialang.org/u/bkamins)\
**Post date:** [December 9, 2022, 10:12am UTC](https://discourse.julialang.org/t/flattening-a-vector-of-vectors/91463/3 "2022-12-09T10:12:05Z")

</div>

Alternatively, if you want it materialized do one of:

```julia
julia> vv = [[1,2], [3,4]]
2-element Vector{Vector{Int64}}:
 [1, 2]
 [3, 4]

julia> vcat(vv...)
4-element Vector{Int64}:
 1
 2
 3
 4

julia> reduce(vcat, vv)
4-element Vector{Int64}:
 1
 2
 3
 4

```

---

<div class="post-metadata">

**Author:** ![Nash](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nash/32/14482_2.png) [@Nash](https://discourse.julialang.org/u/Nash)\
**Post date:** [December 9, 2022, 10:15am UTC](https://discourse.julialang.org/t/flattening-a-vector-of-vectors/91463/4 "2022-12-09T10:15:55Z")

</div>

> [@bkamins](#):
>
> `reduce(vcat, vv)`

reduce(vcat, vv) worked in my case
