Python中的 numpy.random.gamma()
借助numpy.random.gamma()方法,我们可以获取 gamma 分布的随机样本,并使用该方法返回 numpy 数组的随机样本。
Syntax : numpy.random.gamma(shape, scale=1.0, size=None)
Return : Return the random samples of numpy array.
示例 #1:
在这个例子中我们可以看到,通过使用numpy.random.gamma()方法,我们能够从 gamma 分布中获取随机样本,并使用该方法返回随机样本。
Python3
# import numpy and gamma
import numpy as np
import matplotlib.pyplot as plt
# Using gamma() method
gfg = np.random.gamma(3, 20, 1000)
count, bins, ignored = plt.hist(gfg, 14, density = True)
plt.show()
Python3
# import numpy and gamma
import numpy as np
import matplotlib.pyplot as plt
# Using gamma() method
gfg = np.random.gamma(4.98, 12, 40000)
gfg1 = np.random.gamma(gfg, 13.46, 40000)
count, bins, ignored = plt.hist(gfg1, 50, density = True)
plt.show()
输出 :
示例 #2:
Python3
# import numpy and gamma
import numpy as np
import matplotlib.pyplot as plt
# Using gamma() method
gfg = np.random.gamma(4.98, 12, 40000)
gfg1 = np.random.gamma(gfg, 13.46, 40000)
count, bins, ignored = plt.hist(gfg1, 50, density = True)
plt.show()
输出 :