How can I create an iterator on the product of arrays, from an array of arrays? The Array size not predetermined.
Basically the following works as I wish:
for i in Base.Iterators.product([1,2,3],[4,5])
print(i)
end
(1, 4)(2, 4)(3, 4)(1, 5)(2, 5)(3, 5)
But I would like it to work for an array of arrays, but I am getting different result:
x = [[1,2,3],[4,5]]
for i in Base.Iterators.product(x)
print(i)
end
([1, 2, 3],)([4, 5],)
You can use the splat operator to interpolate the array of arrays into the function call:
julia> x = [[1,2,3],[4,5]];
julia> for i in Base.Iterators.product(x...)
print(i)
end
(1, 4)(2, 4)(3, 4)(1, 5)(2, 5)(3, 5)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With