I want to write a function that takes in a list of integers (e.g. L = [0,1,-1]
) and a single integer (e.g. n = 3
) and returns all of the (e.g. triplets) of that list: [0,0,0],[0,0,1],...[-1,-1,-1]
of which there will be len(L)**n
. If I'm committed to n=3
, I could do:
np.array(np.meshgrid(L,L,L)).T.reshape(-1,3)
However, if I want to change that 3 to a different number, I would need to enter my list into meshgrid n times. Is there a slick way of doing this that will work for arbitrary n
? I hope what I'm trying to do makes some sense. It seems like the sort of thing a function would already exist for, but I can't seem to find anything.