# How to convert Array/Vector{Array{Float64,2}} into an Array{Float64,2} OR how to create plots from them?

**URL:** <https://discourse.julialang.org/t/how-to-convert-array-vector-array-float64-2-into-an-array-float64-2-or-how-to-create-plots-from-them/40942>\
**Category:** New to Julia\
**Created:** [June 7, 2020, 6:04pm UTC](https://discourse.julialang.org/t/how-to-convert-array-vector-array-float64-2-into-an-array-float64-2-or-how-to-create-plots-from-them/40942 "2020-06-07T18:04:03Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![HelgavonLichtenstein](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/helgavonlichtenstein/32/5005_2.png) [@HelgavonLichtenstein](https://discourse.julialang.org/u/HelgavonLichtenstein)\
**Post date:** [June 7, 2020, 6:04pm UTC](https://discourse.julialang.org/t/how-to-convert-array-vector-array-float64-2-into-an-array-float64-2-or-how-to-create-plots-from-them/40942/1 "2020-06-07T18:04:03Z")

</div>

Hello, I would like to know how to convert from an `Array`/`Vector{Array{Float64,2}}` into `Array{Float64,2}` or how I can create a plot from them.

I can convert a

```julia
Vector{Array{Float64,2}} with 50001 elements
1×8 Array{Float64,2}:
1×8 Array{Float64,2}:
...

```

into a

```julia
50001×1 Array{Array{Float64,2},2}:
 [0.0 0.711225 … 0.0013899305857990158 -6.671582721176745e-7]
 [1.0 0.7113210329556476 … 0.0013897332870554818 -6.671582721176745e-7]
...

```

But what I’d prefer is a `50001×8 Array{Float64,2}:` as I can then convert it to a `DataFrame` and  
I know how to plot from there. I’ve look at documentation and googled, but I can’t find anything. I apologize if this is something obvious.

---

<div class="post-metadata">

**Author:** ![AndiMD](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/andimd/32/6531_2.png) [@AndiMD](https://discourse.julialang.org/u/AndiMD)\
**Post date:** [June 7, 2020, 6:13pm UTC](https://discourse.julialang.org/t/how-to-convert-array-vector-array-float64-2-into-an-array-float64-2-or-how-to-create-plots-from-them/40942/2 "2020-06-07T18:13:21Z")

</div>

Hi! How about this?

```julia
a = [Matrix([rand() for i=1:8]') for j=1:3] # Array{Array{Float64,2},1}
b = reduce(vcat,a) # Array{Float64,2}

```

---

<div class="post-metadata">

**Author:** ![HelgavonLichtenstein](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/helgavonlichtenstein/32/5005_2.png) [@HelgavonLichtenstein](https://discourse.julialang.org/u/HelgavonLichtenstein)\
**Post date:** [June 7, 2020, 6:27pm UTC](https://discourse.julialang.org/t/how-to-convert-array-vector-array-float64-2-into-an-array-float64-2-or-how-to-create-plots-from-them/40942/3 "2020-06-07T18:27:05Z")

</div>

> [@AndiMD](#):
>
> `b = reduce(vcat,a)`

Wonderful!

Do you have advice on how to search for answers like this in the documentation?

---

<div class="post-metadata">

**Author:** ![rveltz](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rveltz/32/2707_2.png) [@rveltz](https://discourse.julialang.org/u/rveltz)\
**Post date:** [June 7, 2020, 6:40pm UTC](https://discourse.julialang.org/t/how-to-convert-array-vector-array-float64-2-into-an-array-float64-2-or-how-to-create-plots-from-them/40942/4 "2020-06-07T18:40:03Z")

</div>

See also VectorOfArray from `https://github.com/SciML/RecursiveArrayTools.jl`

---

<div class="post-metadata">

**Author:** ![AndiMD](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/andimd/32/6531_2.png) [@AndiMD](https://discourse.julialang.org/u/AndiMD)\
**Post date:** [June 7, 2020, 7:23pm UTC](https://discourse.julialang.org/t/how-to-convert-array-vector-array-float64-2-into-an-array-float64-2-or-how-to-create-plots-from-them/40942/5 "2020-06-07T19:23:59Z")

</div>

Unfortunately, this a little tricky to find, because it combines two functions/concepts:

1. Vertical array concatenation with `vcat` [https://docs.julialang.org/en/v1/base/arrays/#Concatenation-and-permutation-1](https://docs.julialang.org/en/v1/base/arrays/#Concatenation-and-permutation-1)  
There, you find the solution `b = vcat(a...)`  
This works in your scenario, but can be slow if `a` has a large number of elements.
2. The `reduce` function. It is not easy to find in your context, because it is very generic and is used for many things in functional programming. Its one of these functions that is worth always keeping in mind when using Julia.

I feel the documentation of `cat` could reference `reduce`, because you’re not the first person to ask this…

---

<div class="post-metadata">

**Author:** ![Elrod](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/elrod/32/22461_2.png) [@Elrod](https://discourse.julialang.org/u/Elrod)\
**Post date:** [June 7, 2020, 7:39pm UTC](https://discourse.julialang.org/t/how-to-convert-array-vector-array-float64-2-into-an-array-float64-2-or-how-to-create-plots-from-them/40942/6 "2020-06-07T19:39:08Z")

</div>

> [@AndiMD](#):
>
> `Matrix([rand() for i=1:8]')`

Not relevant to the question, but

```julia
julia> rand(1,8)
1×8 Array{Float64,2}:
 0.466874 0.26308 0.105319 0.947792 0.916321 0.975012 0.959983 0.361349

```

is simpler.

---

<div class="post-metadata">

**Author:** ![Seif\_Shebl](https://avatars.discourse-cdn.com/v4/letter/s/eada6e/32.png) [@Seif\_Shebl](https://discourse.julialang.org/u/Seif_Shebl)\
**Post date:** [June 7, 2020, 11:13pm UTC](https://discourse.julialang.org/t/how-to-convert-array-vector-array-float64-2-into-an-array-float64-2-or-how-to-create-plots-from-them/40942/7 "2020-06-07T23:13:25Z")

</div>

Two other options; choose first for speed or second for compactness:

```julia
julia> a = [rand(1,8) for j=1:3]
3-element Array{Array{Float64,2},1}:
 [0.10125963142469918 0.034107265019388766 … 0.62765959243681 0.5979593698724655]
 [0.9642252312080619 0.6314535023806402 … 0.7191877977658307 0.13816813789137528]
 [0.07586919612074938 0.36551814184760767 … 0.13870916326032479 0.85237811990861]

julia> [a[i][j] for i = 1:3, j = 1:8]
3×8 Array{Float64,2}:
 0.10126 0.0341073 0.846837 0.194128 0.119424 0.327054 0.62766 0.597959
 0.964225 0.631454 0.245285 0.64749 0.682603 0.914577 0.719188 0.138168
 0.0758692 0.365518 0.801229 0.561955 0.366092 0.407825 0.138709 0.852378

julia> vcat(a...)
3×8 Array{Float64,2}:
 0.10126 0.0341073 0.846837 0.194128 0.119424 0.327054 0.62766 0.597959
 0.964225 0.631454 0.245285 0.64749 0.682603 0.914577 0.719188 0.138168
 0.0758692 0.365518 0.801229 0.561955 0.366092 0.407825 0.138709 0.852378

```
