Skip to content

Instantly share code, notes, and snippets.

@ry

ry/split.py Secret

Created March 23, 2018 04:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ry/6a284a67eb0118f97b97889ee0309e76 to your computer and use it in GitHub Desktop.
Save ry/6a284a67eb0118f97b97889ee0309e76 to your computer and use it in GitHub Desktop.
import sys
import os.path
import numpy as np
n = int(sys.argv[1])
assert 1 < n < 100
fn = sys.argv[2]
pattern = fn.rsplit(".", 1)[0] + "_%02d.npy"
x = np.load(fn)
nx = x.shape[0] / n
assert(x.shape[0] % n == 0);
print "examples per shard", nx
for i in range(n):
sfn = pattern % i
s = x[nx*i: nx*(i+1)]
np.save(sfn, s)
print i, sfn
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment