I want to find effective permutations of a vector that binds values.
For example, if perm_vector = [0,0,1,2] , I would like to get all combinations [0,0,1,2], [0,0,2,1], [0,1,2,0] as an output [0,0,1,2], [0,0,2,1], [0,1,2,0] , etc., but I do not want to get [0,0,1,2] twice, which will give the standard itertools.permutations(perm_vector) .
I tried the following, but it works very slowly when perm_vector grows in len:
vectors_list = [] for it in itertools.permutations(perm_vector): vectors_list.append(list(it)) df_vectors_list = pd.DataFrame( vectors_list) df_gb = df_vectors_list.groupby(list(df_vectors_list.columns)) vectors_list = pd.DataFrame(df_gb.groups.keys()).T
The question of a more general "accelerated" character, in fact. Most of the time is spent on creating permutations of long vectors - even without duplicity, creating permutations of a vector of 12 unique values ββtakes "infinity". Is it possible to call itertools iteratively, without accessing all the permutation data, but working on bundles?