Combinations across arrays

I have three arrays:

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:

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!

Maybe:

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)
...
3 Likes

Also, if you like comprehensions:

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]
 ⋮
1 Like