In [1]:
import numpy as np
a = np.random.poisson(5, 100000)
In [2]:
import matplotlib
import matplotlib.pyplot as plt
%matplotlib inline
count, bins, ignored = plt.hist(a, 14, normed=True)
plt.show()
In [40]:
def misra_gries(arr, k):
m = arr.shape[0]
frq = {}
for x in arr:
if x in frq:
frq[x] += 1
elif len(frq.keys())<k:
frq[x] = 1
else:
for key in frq.keys():
frq[key] -= 1
frq = { key : val for key,val in frq.items() if k == 0 }
return(frq)
## test
t = np.array([1,2,1,5,3,1,2,4,1,4,2,1,1,2])
misra_gries(t, 3)
Out[40]:
In [41]:
misra_gries(a, 10)
Out[41]:
In [43]:
res = misra_gries(a, 10)
x,y = list(res.keys()), list(res.values())
plt.plot(x, y)
plt.show()
In [ ]: