In Julia’s Iterators.product, the first iterator changes the fastest. Is there an easy way to get elements in an order, so that the last iterator changes the fastest? For example with three sequences, I obtain:
res = Iterators.product([:A, :B, :C], [:X, :Y], [1,2]) |> collect
3×2×2 Array{Tuple{Symbol, Symbol, Int64}, 3}:
[:, :, 1] =
(:A, :X, 1) (:A, :Y, 1)
(:B, :X, 1) (:B, :Y, 1)
(:C, :X, 1) (:C, :Y, 1)
[:, :, 2] =
(:A, :X, 2) (:A, :Y, 2)
(:B, :X, 2) (:B, :Y, 2)
(:C, :X, 2) (:C, :Y, 2)
If I get elements using res[:]
I obtain:
julia> res[:]
12-element Vector{Tuple{Symbol, Symbol, Int64}}:
(:A, :X, 1)
(:B, :X, 1)
(:C, :X, 1)
(:A, :Y, 1)
(:B, :Y, 1)
(:C, :Y, 1)
(:A, :X, 2)
(:B, :X, 2)
(:C, :X, 2)
(:A, :Y, 2)
(:B, :Y, 2)
(:C, :Y, 2)
Instead, I want:
(:A, :X, 1)
(:A, :X, 2)
(:A, :Y, 1)
(:A, :Y, 2)
(:B, :X, 1)
(:B, :X, 2)
(:B, :Y, 2)
(:B, :Y, 2)
(:C, :X, 1)
(:C, :X, 2)
(:C, :Y, 2)
(:C, :Y, 2)
What is the easiest way to get that from the res
variable? Thank you!