# Combinations across arrays

**URL:** https://discourse.julialang.org/t/combinations-across-arrays/52847
**Category:** General Usage
**Tags:** question, package
**Created:** [January 4, 2021, 9:01pm UTC](https://discourse.julialang.org/t/combinations-across-arrays/52847 "2021-01-04T21:01:05Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![danicaratelli](https://avatars.discourse-cdn.com/v4/letter/d/90db22/32.png) [@danicaratelli](https://discourse.julialang.org/u/danicaratelli)
#### Post date: [January 4, 2021, 9:01pm UTC](https://discourse.julialang.org/t/combinations-across-arrays/52847/1 "2021-01-04T21:01:05Z")

</div>

I have three arrays:

```julia
a=[1,2,3];
b=[4,5,6];
c=[7,8,9];

```

and I want to get all possible combinations across the three arrays with three elements, the first from `a`, the second from `b`, and the third from `c`. That is:

```julia
result = [[1,4,7];[1,4,8];[1,4,9];[1,5,7];[1,5,8],...]

```

Is there a quick way to do, maybe using `Combinatorics.jl` ` or one of the other existing packages?

Thank you!

---

<div class="post-metadata">

### Author: ![mcabbott](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mcabbott/32/6603_2.png) [@mcabbott](https://discourse.julialang.org/u/mcabbott)
#### Post date: [January 4, 2021, 9:09pm UTC](https://discourse.julialang.org/t/combinations-across-arrays/52847/2 "2021-01-04T21:09:00Z")

</div>

Maybe:

```julia
julia> Iterators.product(a,b,c) |> collect |> vec
27-element Vector{Tuple{Int64, Int64, Int64}}:
 (1, 4, 7)
 (2, 4, 7)
 (3, 4, 7)
 (1, 5, 7)
 (2, 5, 7)
 (3, 5, 7)
...

```

---

<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: [January 4, 2021, 10:11pm UTC](https://discourse.julialang.org/t/combinations-across-arrays/52847/3 "2021-01-04T22:11:51Z")

</div>

Also, if you like comprehensions:

```julia
julia> [[i,j,k] for i in a for j in b for k in c]
27-element Array{Array{Int64,1},1}:
 [1, 4, 7]
 [2, 4, 7]
 [3, 4, 7]
 [1, 5, 7]
 [2, 5, 7]
 [3, 5, 7]
 ⋮

```
