Created
May 29, 2012 16:19
-
-
Save mtholder/2829324 to your computer and use it in GitHub Desktop.
Log of the mean of the exp of values from standard input
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
#!/usr/bin/env python | |
import sys, math | |
v_list = [float(value) for value in sys.stdin] | |
offset = max(v_list) | |
n = len(v_list) | |
sum_exps = sum([math.exp(v - offset) for v in v_list]) | |
mean_exps = sum_exps/n | |
sys.stdout.write('Log of mean of the exp of %d values is:\n' % n) | |
sys.stdout.write('%8.7f\n' % (math.log(mean_exps) + offset)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment