# How to stack vectors to make a matrix?

**URL:** <https://discourse.julialang.org/t/how-to-stack-vectors-to-make-a-matrix/16010>\
**Category:** New to Julia\
**Created:** [October 8, 2018, 6:25am UTC](https://discourse.julialang.org/t/how-to-stack-vectors-to-make-a-matrix/16010 "2018-10-08T06:25:42Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![xiaodai](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/xiaodai/32/15937_2.png) [@xiaodai](https://discourse.julialang.org/u/xiaodai)\
**Post date:** [October 8, 2018, 6:25am UTC](https://discourse.julialang.org/t/how-to-stack-vectors-to-make-a-matrix/16010/1 "2018-10-08T06:25:42Z")

</div>

Say I have two vectors of the same size and I would like to stack them together to form a matrix, what’s the function to perform that?

```julia
x = [1,2,3]
y = [4,5,6]
z = [7,8,9]
xy = zeros(Int64,2,3)
xy[1,:] = x
xy[2,:] = y
xy

```

I know that this will work, but is there a more efficient way? This needs to generalise to stacking `n` vectors for some `n`.

---

<div class="post-metadata">

**Author:** ![mohamed82008](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mohamed82008/32/18171_2.png) [@mohamed82008](https://discourse.julialang.org/u/mohamed82008)\
**Post date:** [October 8, 2018, 6:29am UTC](https://discourse.julialang.org/t/how-to-stack-vectors-to-make-a-matrix/16010/2 "2018-10-08T06:29:12Z")

</div>

```julia
julia> x = [1,2,3];

julia> y = [4,5,6];

julia> z = [7,8,9];

julia> vecs = (x, y, z);

julia> vcat(transpose.(vecs)...)
3×3 Array{Int64,2}:
 1 2 3
 4 5 6
 7 8 9

```
