# Create matrix by combining vectors element-wise

**URL:** https://discourse.julialang.org/t/create-matrix-by-combining-vectors-element-wise/80373
**Category:** New to Julia
**Tags:** arrays
**Created:** [May 2, 2022, 3:34pm UTC](https://discourse.julialang.org/t/create-matrix-by-combining-vectors-element-wise/80373 "2022-05-02T15:34:56Z")
**Posts on this page:** 1
**Showing post:** 3

<div class="post-metadata">

### Author: ![mbaz](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mbaz/32/17295_2.png) [@mbaz](https://discourse.julialang.org/u/mbaz)
#### Post date: [May 2, 2022, 4:24pm UTC](https://discourse.julialang.org/t/create-matrix-by-combining-vectors-element-wise/80373/3 "2022-05-02T16:24:01Z")

</div>

The solution by @jacobusmmsmit is probably the way to go. For completeness, here’s a way to rewrite your code to be shorter and arguably easier to read:

```julia
julia> combination_vectors(a, b) = vcat(([f s] for f in a for s in b)...)
combination_vectors (generic function with 1 method)

(@v1.7) julia> combination_vectors(a, b)
6×2 Matrix{Int64}:
 1 4
 1 5
 2 4
 2 5
 3 4
 3 5

```

---

_[View the full topic](https://discourse.julialang.org/t/create-matrix-by-combining-vectors-element-wise/80373)._
