Created
April 18, 2016 20:51
-
-
Save jeremiahmarks/e950915d6326a3150ed37a952d9c115c to your computer and use it in GitHub Desktop.
solution to DailyProgrammer From https://www.reddit.com/r/dailyprogrammer/comments/4fc896/20160418_challenge_263_easy_calculating_shannon/d28017p
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 math | |
def getEntropy(somestring): | |
baseent=0.0 | |
lettersinthing=set(somestring) | |
for eachletter in lettersinthing: | |
letent = somestring.count(eachletter)/float(len(somestring)) | |
letent=letent*math.log(letent, 2) | |
baseent+=letent | |
return -1*baseent |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment