Last active
May 16, 2017 15:10
-
-
Save mickypaganini/ef60bd1c7ecb2d5582c099df31a95f8a to your computer and use it in GitHub Desktop.
Not the most intelligent way of doing it, but it works.
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
d = io.load('yourfile.hdf5') | |
#ix = [random.sample(range(4), 4) for _ in xrange(d['X'].shape[0])] | |
ix = np.argsort(d['X'][:, :4])[:, ::-1] | |
def _pairwise(iterable): | |
'''s -> (s0, s1), (s2, s3), (s4, s5), ...''' | |
a = iter(iterable) | |
return izip(a, a) | |
cols = list(_pairwise(range(d['X'].shape[-1])[::4])) # or you can just type [(0, 4), (8, 12), (16, 20), (24, 28)] | |
for slc in cols: | |
print 'Shuffling columns {}'.format(slc) | |
d['X'][:, slice(*slc)] = np.array([row[sh] for row, sh in zip(d['X'][:, slice(*slc)], ix)]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment