# How to get all combinations from multiple input arrays?

**URL:** https://discourse.julialang.org/t/how-to-get-all-combinations-from-multiple-input-arrays/100010
**Category:** General Usage
**Tags:** question
**Created:** [June 7, 2023, 3:15pm UTC](https://discourse.julialang.org/t/how-to-get-all-combinations-from-multiple-input-arrays/100010 "2023-06-07T15:15:52Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![ejmeitz](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ejmeitz/32/45283_2.png) [@ejmeitz](https://discourse.julialang.org/u/ejmeitz)
#### Post date: [June 7, 2023, 3:15pm UTC](https://discourse.julialang.org/t/how-to-get-all-combinations-from-multiple-input-arrays/100010/1 "2023-06-07T15:15:52Z")

</div>

Hello,

Say I have three input arrays like the ones below (could be arbitrary amount) and I want to generate all possible combinations of values with one entry from each array. The existing functions in Combinatorics.jl only work with one array (e.g. [:a, 1, “hi”], [:a,1,“bye”], [:a,2,“hi”]). If I knew I would always have three arrays I could just loop but I do not know beforehand if I will have 2 or 3 or 4 etc arrays to generate combinations from. Is there any way to do this that I’m just missing or some package I don’t know of?

Thanks!

```julia
letters = [:a, :b, :c]
numbers = [1,2,3]
other = ["hi", "bye"]

```

---

<div class="post-metadata">

### Author: ![stillyslalom](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stillyslalom/32/45687_2.png) [@stillyslalom](https://discourse.julialang.org/u/stillyslalom)
#### Post date: [June 7, 2023, 3:24pm UTC](https://discourse.julialang.org/t/how-to-get-all-combinations-from-multiple-input-arrays/100010/2 "2023-06-07T15:24:18Z")

</div>

```julia
julia> allcombinations(v...) = vec(collect(Iterators.product(v...)))
allcombinations (generic function with 1 method)

julia> allcombinations(letters, numbers, other)
18-element Vector{Tuple{Symbol, Int64, String}}:
 (:a, 1, "hi")
 (:b, 1, "hi")
 (:c, 1, "hi")
 (:a, 2, "hi")
 (:b, 2, "hi")
 (:c, 2, "hi")
 (:a, 3, "hi")
 (:b, 3, "hi")
 (:c, 3, "hi")
 (:a, 1, "bye")
 (:b, 1, "bye")
 (:c, 1, "bye")
 (:a, 2, "bye")
 (:b, 2, "bye")
 (:c, 2, "bye")
 (:a, 3, "bye")
 (:b, 3, "bye")
 (:c, 3, "bye")

```

---

<div class="post-metadata">

### Author: ![ejmeitz](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ejmeitz/32/45283_2.png) [@ejmeitz](https://discourse.julialang.org/u/ejmeitz)
#### Post date: [June 7, 2023, 3:25pm UTC](https://discourse.julialang.org/t/how-to-get-all-combinations-from-multiple-input-arrays/100010/3 "2023-06-07T15:25:46Z")

</div>

Thank you!

---

<div class="post-metadata">

### Author: ![nilshg](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nilshg/32/2283_2.png) [@nilshg](https://discourse.julialang.org/u/nilshg)
#### Post date: [June 7, 2023, 3:49pm UTC](https://discourse.julialang.org/t/how-to-get-all-combinations-from-multiple-input-arrays/100010/4 "2023-06-07T15:49:25Z")

</div>

Note that you generally want to avoid `collect` which materialises the iterator if you can avoid it.
