Сначала у меня вот это:
Код: Выделить всё
ncombos = itertools.combinations_with_replacement(['a1', 'a2', 'a3'], years*n)
('a1', 'a1', 'a1')
('a1', 'a1', 'a2')
('a1', 'a1', 'a3')
('a1', 'a2', 'a2')
.... etc.....
('a3', 'a3', 'a3')
Код: Выделить всё
nodes = np.ones(len(leafs)); i=0 #This will store the number of permutations
for j in ncombos:
nodes[i] =len(list(set(itertools.permutations(np.asanyarray(j), n))))
i = i+1
По сути, все, что мне нужно, это подсчитать количество перестановок... Однако мой код чрезвычайно!!! медленный ! Спасибо!
Подробнее здесь: https://stackoverflow.com/questions/164 ... -in-python
Мобильная версия