2017-08-02 11 views
1
Python 3.6.1 :: Anaconda custom (64-bit) 

import numpy as np 
import matplotlib.pyplot as plt 
import matplotlib as mtptlb 

print (np.__version__) 
1.12.1 
print (mtptlb.__version__) 
2.0.2 

%matplotlib inline 
a=np.random.uniform(1,100,1000000) 
b=range(1,101) 
plt.hist(a) 

enter image description herePythonのnumpyの乱数確率

なぜY軸はを示していますか? np.random.uniform(1,100,)の値は1000000なので、y軸に1000000を表示しないでください。

答えて

7

デフォルトでは、matplotlib.pyplot.histは10ビンを使用します。したがって、100万のすべての値が10個のビンに分配されます。完璧な一様分布の場合、各ビンに100,000回の出現(100万分の10)があることが予想されます。

あなたはすなわち

a=np.random.uniform(1, 100, 1000000) 
plt.hist(a, bins=100) 

enter image description here

ここでは、全てのビンが10000

それともでおよそある100個のビンに分割され、それが均一に分布だからだ、ビンの数を変更することができますあなたが1 000のカウントをしたい場合は1つのビン000:

a=np.random.uniform(1, 100, 1000000) 
plt.hist(a, bins=1) 

enter image description here