[5-1] 必要なモジュールをインポートします。
In [1]:
import numpy as np
import matplotlib.pyplot as plt
from numpy.random import random
from numpy.random import normal
[5-2] randomを用いて、0〜1の範囲の乱数を5個発生します。
In [2]:
print random(5)
[5-3] 100〜150の範囲の乱数を5個発生します。
In [3]:
print 100+random(5)*50
[5-4] normalを用いて、正規分布の乱数を発生します。ここでは、標準偏差1の場合と標準偏差2の場合をグラフで比較しています。
In [4]:
fig = plt.figure(figsize=(5,6))
subplot = fig.add_subplot(2,1,1)
data = normal(5,1,1000)
subplot.hist(data, bins=np.linspace(0,10,20))
subplot = fig.add_subplot(2,1,2)
data = normal(5,2,1000)
subplot.hist(data, bins=np.linspace(0,10,20))
Out[4]: