Skip to content

Instantly share code, notes, and snippets.

@galenseilis
Created October 16, 2022 04:50
Show Gist options
  • Select an option

  • Save galenseilis/2df0c3edfb1e3c46db04e167df4080fa to your computer and use it in GitHub Desktop.

Select an option

Save galenseilis/2df0c3edfb1e3c46db04e167df4080fa to your computer and use it in GitHub Desktop.
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