SHARE
TWEET

Untitled

a guest May 19th, 2019 58 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import tensorflow as tf
  2. import pandas as pd
  3. import numpy as np
  4. from scipy import stats
  5. import itertools
  6. import matplotlib.pylab as plt
  7.  
  8. # 白努力分配
  9. size = 10000
  10. p = 0.4
  11. data_bern = stats.bernoulli.rvs(size=size, p=p)
  12. plt.hist(data_bern)
  13.  
  14. bernDf = pd.DataFrame({'試驗': data_bern})
  15. print('0的機率:', len(bernDf[bernDf['試驗'] == 0])/size)
  16. print('1的機率:', len(bernDf[bernDf['試驗'] == 1])/size)
  17.  
  18. rs = [len(list(v)) for k,v in itertools.groupby(data_bern) if k == 1]
  19. print('最大連續次數:', max(rs))
  20. print('機率:', max(rs)/size)
  21. plt.hist(rs)
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top