Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download

Jupyter notebook benford.ipynb

212 views
Kernel: Python 3 (Anaconda)

Benford's Law Example

import numpy as np import matplotlib.pyplot as plt
# first digit of a number def firstDigit(n): string = str(n) return int(string[0])
# exponentiate and track first digit at each step def benford(num,iter): arrNum = [num] for i in range(iter): arrNum.append(arrNum[-1]*num) return [firstDigit(n) for n in arrNum]
# histogram for 2.04 plt.hist(benford(2.04,100),bins=9) plt.show()
Image in a Jupyter notebook