Created
January 11, 2012 18:56
-
-
Save alaiacano/1596181 to your computer and use it in GitHub Desktop.
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
import numpy as np | |
import random | |
# dict to hold results | |
counts = {} | |
# a hack to generate random key, value pairs. | |
# 5k keys, 100k values | |
x=[i%5000 for i in xrange(100000)] | |
random.shuffle(x) | |
kv = np.array(zip(x, np.random.uniform(0, 1, 100000))) | |
# groupby sum | |
for k, v in kv: | |
try: | |
counts[k] += v | |
except KeyError: | |
counts[k] = v | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment