All pastes #839357 Raw Edit

Something

public text v1 · immutable
#839357 ·published 2007-12-30 23:59 UTC
rendered paste body
def entropy(l):

  from math import log
  log2=lambda x:log(x)/log(2)
  total=len(l)
  counts={}

  for item in l:
    counts.setdefault(item,0)
    counts[item]+=1

  ent=0

  for i in counts:
    p=float(counts[i])/total
    ent-=p*log2(p)

  return ent