code: def __entropy(data):
      '''Compute entropy of the flattened data set (e.g. a density distribution).'''
      # normalize and convert to float
      data = data/float(numpy.sum(data))
      # for each grey-value g with a probability p(g) = 0, the entropy is defined as 0, therefore we remove these values and also flatten the histogram
      data = data[numpy.nonzero(data)]
      # compute entropy
      return -1. * numpy.sum(data * numpy.log2(data)f __entropy(data):
      '''Compute entropy of the flattened data set (e.g. a density distribution).'''
      # normalize and convert to float
      data = data/float(numpy.sum(data))
      # for each grey-value g with a probability p(g) = 0, the entropy is defined as 0, therefore we remove these values and also flatten the histogram
      data = data[numpy.nonzero(data)]
      # compute entropy
      return -1. * numpy.sum(data * numpy.log2(data))
docs: Compute entropy of the flattened data set (e.g. a density distribution).