#----------------------------------------------------------------# Sample code for UEET2533 Information Theory and Coding# by Chong Zan Kai# Email [email protected]# Universiti Tunku Abdul Rahman, Malaysia.## Plot the entropy graph.## Last modified on 2-Feb-2016.#----------------------------------------------------------------## Calculate the information of an event that has binary output.#defcalc_entropy(p):bit=p*log(1/p,2)+(1-p)*log(1/(1-p),2)returnbit#----------------------------------------------------------------# Main#----------------------------------------------------------------importscipyimportpylabx_list=scipy.arange(0.01,1.0,0.01)y_list=[calc_entropy(p)forpinx_list]pylab.plot(x_list,y_list)pylab.ylabel(r'Entropy, $H(X)$')pylab.xlabel(r'Probability, $\Pr(X=1)$')pylab.ylim(0,1.1)pylab.grid(True)pylab.show()
[<matplotlib.lines.Line2D object at 0x7fbc8cab4b50>]
<matplotlib.text.Text object at 0x7fbc8c7b2a10>
<matplotlib.text.Text object at 0x7fbc8cc2f510>
(0, 1.10000000000000)