I want to create a numpy array with all possible combinations of items from multiple lists of different sizes:
a = [1, 2]
b = [3, 4]
c = [5, 6, 7]
d = [8, 9, 10]
In each combination, I want 2 elements. I don't want any duplicates, and I don't want items from the same list to mix together.
I can get all such combinations with 3 elements with np.array(np.meshgrid(a, b, c, d)).T.reshape(-1,3) but I need pairs, not triplets. Doing np.array(np.meshgrid(a, b, c, d)).T.reshape(-1,2) doesn't work because it just cuts off one column of the original array.
Any ideas on how to achieve this?
[i for c in combinations((a, b, c, d), 2) for i in product(*c)]list(chain.from_iterable(starmap(product, combinations((a, b, c, d), 2)))