Skip to content

Instantly share code, notes, and snippets.

@alaiacano
Created January 11, 2012 18:56
Show Gist options
  • Save alaiacano/1596181 to your computer and use it in GitHub Desktop.
Save alaiacano/1596181 to your computer and use it in GitHub Desktop.
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