Skip to content

Instantly share code, notes, and snippets.

@phil8192
Created April 3, 2020 20:24
Show Gist options
  • Save phil8192/cca49e2d54ce7f927cfb7cd6bfdf4dc5 to your computer and use it in GitHub Desktop.
Save phil8192/cca49e2d54ce7f927cfb7cd6bfdf4dc5 to your computer and use it in GitHub Desktop.
def batches(X, y, batch_size, randomise):
rows = X.shape[0]
i = np.arange(rows)
if randomise:
np.random.shuffle(i)
splits = rows / batch_size
for x_batch, y_batch in zip(np.array_split(X[i, ], splits),
np.array_split(y[i], splits)):
yield x_batch, y_batch
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment