Sync
This commit is contained in:
parent
6f050a029e
commit
776bba907c
3887 changed files with 59894 additions and 7280 deletions
10
Task/Entropy/Python/entropy-2.py
Normal file
10
Task/Entropy/Python/entropy-2.py
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
>>> import math
|
||||
>>> from collections import Counter
|
||||
>>>
|
||||
>>> def entropy(s):
|
||||
... p, lns = Counter(s), float(len(s))
|
||||
... return -sum( count/lns * math.log(count/lns, 2) for count in p.values())
|
||||
...
|
||||
>>> entropy("1223334444")
|
||||
1.8464393446710154
|
||||
>>>
|
||||
Loading…
Add table
Add a link
Reference in a new issue