Created
July 7, 2012 14:59
-
-
Save alaiacano/3066775 to your computer and use it in GitHub Desktop.
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
""" | |
Input is one number per line | |
Output is json of the form: | |
[ | |
{ | |
'bin' : bin1, | |
'value' : value1 | |
}, | |
{ | |
'bin' : bin2, | |
'value' : value2 | |
}, | |
] | |
Set UPDATE_EVERY to whatever you want. set it to 10 and you'll get a | |
new histogram output every 10th input | |
Invocation: | |
cat numbers.txt | python -u hists.py | |
""" | |
import sys, numpy | |
UPDATE_EVERY = 5 | |
arr = numpy.array([]) | |
counter = 0 | |
for line in sys.stdin: | |
counter += 1 | |
arr = numpy.append(arr, float(line.strip())) | |
if counter % UPDATE_EVERY == 0: | |
h = numpy.histogram(arr) | |
output = [] | |
for count, bin in zip(h[0], h[1]): | |
output.append({'bin':bin, 'count':count}) | |
print output |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment