当前位置: 首页>>代码示例 >>用法及示例精选 >>正文


Python numpy.random.gamma()用法及代码示例


借助numpy.random.gamma()方法,我们可以获取伽马分布的随机样本,并使用此方法返回numpy数组的随机样本。

伽马分布

用法:numpy.random.gamma(shape, scale=1.0, size=None)

返回:返回numpy数组的随机样本。

范例1:

在此示例中,我们可以看到,通过使用numpy.random.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()

输出:

范例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()

输出:

相关用法


注:本文由纯净天空筛选整理自Jitender_1998大神的英文原创作品 numpy.random.gamma() in Python。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。