Skip to content

Instantly share code, notes, and snippets.

@shubhamagarwal92
Created August 1, 2019 21:47
Show Gist options
  • Save shubhamagarwal92/655a4d86d5c945e6c8b4be5293c8db20 to your computer and use it in GitHub Desktop.
Save shubhamagarwal92/655a4d86d5c945e6c8b4be5293c8db20 to your computer and use it in GitHub Desktop.
Get batch size chunks from list
# Yield successive n-sized
# chunks from l.
def divide_chunks(l, n):
# looping till length l
for i in range(0, len(l), n):
yield l[i:i + n]
test_list = list(range(100))
batch_size = 10
for batch in divide_chunks(test_list, batch_size):
print(batch)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment