2 Entropy Done

Run Settings
LanguagePython
Language Version
Run Command
import numpy as np # generate a random data set on [1,10] data = np.random.randint(low=1,high=10, size=100) print('data = ' + str(data)) # histogram of the data, number of elements with value 1,2,...,10 hist = np.histogram(data,bins=[1,2,3,4,5,6,7,8,9]) print('hist = ' + str(hist)) # number of elements in the histogram. This should be 100 N = np.sum(d for d in hist[0]) print('N = ' + str(N)) # get the entropy : - sum( d*ln(d) ) for the normalized histogram H = -((1./N)*np.sum( d*np.log(d) for d in hist[0]) - np.log(N)) print('H = ' + str(H)) # question: does the entropy depend on the number of elements in data ?
Editor Settings
Theme
Key bindings
Full width
Lines