Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
8
Task/Entropy/Python/entropy-2.py
Normal file
8
Task/Entropy/Python/entropy-2.py
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
from math import log2
|
||||
from collections import Counter
|
||||
|
||||
def entropy(s):
|
||||
p, lns = Counter(s), float(len(s))
|
||||
return log2(lns) - sum(count * log2(count) for count in p.values()) / lns
|
||||
|
||||
print(entropy("1223334444"))
|
||||
Loading…
Add table
Add a link
Reference in a new issue