I am using itertools
to run a numerical simulation iterating over all possible combinations of my input parameters. In the example below, I have two parameters and
While this doesn't answer the question directly, very often we want to find the length of generators to estimate the progress/runtime.
For this, do consider using tqdm
's (version >= 4.42.0) wrappers around generator functions that don't forget the lengths of iterators (tqdm
is a progressbar library). E.g.,
from tqdm.contrib.itertools import product
from time import sleep
for i, j in product(range(3), range(4)):
sleep(1)
will show a progress bar. The length of the product is shown as the total
of the tqdm
object (e.g.., the 6
in 3/6 [00:03<00:03]
shown).