Created
October 16, 2022 04:50
-
-
Save galenseilis/2df0c3edfb1e3c46db04e167df4080fa to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import matplotlib.pyplot as plt | |
| import numpy as np | |
| from mpmath import * | |
| mp.pretty = True | |
| nseq = range(1, 10001) | |
| hseq = [] | |
| for i in nseq: | |
| mp.dps = i | |
| x, fx = np.unique(list(str(pi).replace('.', '')), return_counts=True) | |
| total = np.sum(fx) | |
| px = fx / total | |
| hx = -np.sum(px * np.log2(px)) / np.log2(px.size) | |
| hseq.append(hx) | |
| plt.step(nseq, hseq) | |
| plt.xlabel('n') | |
| plt.ylabel('Shannon Entropy') | |
| plt.show() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment