Given a matrix, how can I quickly generate all tuples consisting of its row elements in python? [duplicate]
Solution 1:
itertools.product
Example:
In [1]: import itertools
In [2]: arr = [[1, 2], [3, 4], [5, 6]]
In [3]: list(itertools.product(*arr))
Out[3]:
[(1, 3, 5),
(1, 3, 6),
(1, 4, 5),
(1, 4, 6),
(2, 3, 5),
(2, 3, 6),
(2, 4, 5),
(2, 4, 6)]