-
-
Save Riverfount/0d85f7ec273272bdf7cbb933f566e381 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def generate_batch(generator, batch_size=10): | |
batch = [] | |
for e in generator: | |
if len(batch) == batch_size: | |
yield batch | |
batch = [] | |
batch.append(e) | |
if batch: | |
yield batch | |
if __name__ == '__main__': | |
for batch in generate_batch(range(23), 10): | |
print(batch) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment