Skip to content

Instantly share code, notes, and snippets.

@lockdef
Created July 12, 2019 01:51
Show Gist options
  • Save lockdef/6f0c259e4d4fec2ce0f5e46fdb09aad7 to your computer and use it in GitHub Desktop.
Save lockdef/6f0c259e4d4fec2ce0f5e46fdb09aad7 to your computer and use it in GitHub Desktop.
平均エントロピーの関数
import math
def avg_entropy(num_arr):
num_arr = list(map(lambda x: x * math.log2(x), num_arr))
return -sum(num_arr)
if __name__=='__main__':
input_num = [0.05, 0.25, 0.70]
output = avg_entropy(input_num)
print('output :', output)
# output : 1.0762976257251988
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment