Last active
January 11, 2016 11:36
-
-
Save ryuichimatsumoto-single/b019343bf9f2adc00b7b to your computer and use it in GitHub Desktop.
サイコロをn回振った時の出目をシュミレーション(A roll of the dice)
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
| # coding: UTF-8 | |
| # サイコロを100回振った時の出目をシュミレーション(モンテカルロ法) | |
| # 乱数は1〜6が同様に出る乱数(恐らく一様乱数)を使用 | |
| # 詳細は「http://qiita.com/yubais/items/bf9ce0a8fefdcc0b0c97」 | |
| import numpy as np | |
| N= 100 #サイコロを振る回数 | |
| list = np.arange(N) | |
| num = np.zeros(7) | |
| for n in range(0,N): | |
| #ここが計測手法f(X)の部分(1〜6の出目を生成) | |
| list[n] = np.random.randint(1,7) | |
| for m in range(0,7): | |
| if m == list[n]: | |
| num[m] = num[m] + 1#出目の回数をここでカウント | |
| print list #100回の出目を出力 | |
| print num #出目が何回出たか出力 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment