NumPy standard_cauchy () 随机样本生成


发布日期 : 2020-12-07 08:59:50 UTC

访问量: 9 次浏览

Python numpy.random.standard_cauchy()

numpy.random.standard_cauchy() 方法的帮助下,我们可以看到从标准柯西(Cauchy)分布中获取随机样本,并返回随机样本。

numpy.random.standard_cauchy()

标准柯西分布

语法:
numpy.random.standard_cauchy(size=None)

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

例子 #1:

在这个例子中,我们可以看到,通过使用 numpy.random.standard_cauchy() 方法,我们能够获得标准柯西分布的随机样本,并从中生成随机样本。

# import numpy
import numpy as np
import matplotlib.pyplot as plt
  
# Using standard_cauchy() method
gfg = np.random.standard_cauchy(100000)
  
gfg = gfg[(gfg>-25) & (gfg<25)]
plt.hist(gfg, bins = 100, density = True)
plt.show()

输出 :

Python numpy.random.standard_cauchy()

例子 #2 :

# import numpy
import numpy as np
import matplotlib.pyplot as plt
  
# Using standard_cauchy() method
gfg = np.random.standard_cauchy(100000)
gfg1 = np.random.power([gfg>0], 100000)
  
plt.hist(gfg1, bins = 100, density = True)
plt.show()

输出 :

Python numpy.random.standard_cauchy()