Reputation: 479
Using Julia 1.0.1, I want to obtain a vector of all combinations of 5 objects, the objects being the [1,2], and each of the number 3,4,5 and 6
I have created an object a = [[1,2],3,4,5,6]
and obtained the combinations.
using Combinatorics
a = [[1,2],3,4,5,6]
anas5 = collect(combinations(a))
As expected, I am obtaining
31-element Array{Array{Any,1},1}:
[[1, 2]]
[3]
[4]
[5]
[6]
[[1, 2], 3]
...
How can I transform the results so that the combinations including [1, 2] become a vector. For example, so the first few lines described above become:
[1, 2]
[3]
[4]
[5]
[6]
[1, 2, 3]
...
Thank you
Upvotes: 1
Views: 50
Reputation: 331
You can use Iterators.flatten
to flatten your Vector of Vectors.
collect.(Iterators.flatten.(anas5))
Upvotes: 2