Created
July 9, 2018 13:53
-
-
Save yang-zhang/df2ee069436ef70abc40f17fdb63428c to your computer and use it in GitHub Desktop.
Randomly sample a dictionary
This file contains hidden or 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 sample_dct(dct, n=3): | |
idx = np.random.choice(len(dct), n) | |
return dict(np.array(list(dct.items()))[idx]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment