ertk.utils.batch_iterable
- ertk.utils.batch_iterable(it: Iterable[T], batch_size: int, return_last: bool = True) Iterable[Tuple[T, ...]]
Batches an iterable into chunks of size
batch_size.- Parameters:
- it: iterable
The iterable to batch.
- batch_size: int
The size of each batch/chunk.
- return_last: bool
Whether to yield the last batch if it isn’t full (i.e.
batch_sizedoesn’t divide the iterable length.)
- Yields:
- tuple
A tuple of length
batch_sizewith successive elements from the original iterable. Ifreturn_last == Falsethen the last batch is dropped if it contains less thanbatch_sizeitems.