My question is similar to this one, but rather I want to find all possible vectors of a given size comprising [x,y,...]
elements. For instance, given a list [1,2]
, how do I find all possible vectors with elements 1
and 2
, with size 3? in this case it is:
(1,1,1)
(1,1,2)
(1,2,1)
(2,1,1)
(1,2,2)
(2,1,2)
(2,2,1)
(2,2,2)
What is an elegant way to do this? I'm imagining that subsequent for
loops is not the best way to do this. In my real case I am actually looking for $2^{8}$ combinations since I am looking for vectors with 8 elements.