In [30]: num_list = [1, 2, 3]
In [31]: from itertools import combinations
In [32]: comb = combinations(num_list,2)
In [33]: for pair in list(comb): ...: print(pair) ...: (1, 2) (1, 3) (2, 3)
In [47]: from itertools import product
In [48]: params = { ...: "learning_rate": [1e-1, 1e-2, 1e-3], ...: "batch_size": [16, 32, 64], ...: }
In [49]:
In [49]:
In [49]:
In [49]: for vals in product(*params.values()): ...: combination = dict(zip(params.keys(), vals)) ...: print(combination) ...: {'learning_rate': 0.1, 'batch_size': 16} {'learning_rate': 0.1, 'batch_size': 32} {'learning_rate': 0.1, 'batch_size': 64} {'learning_rate': 0.01, 'batch_size': 16} {'learning_rate': 0.01, 'batch_size': 32} {'learning_rate': 0.01, 'batch_size': 64} {'learning_rate': 0.001, 'batch_size': 16} {'learning_rate': 0.001, 'batch_size': 32} {'learning_rate': 0.001, 'batch_size': 64}
In [50]:
In [56]: def multiple(x,y): ...: return x*y ...:
In [57]: nums = [(1, 2), (4, 2), (2, 5)]
In [58]: from itertools import starmap
In [59]: list(starmap(multiple,nums)) Out[59]: [2, 8, 10]
In [60]: