numpy.random.normal()官方文档翻译

numpy.random.normal(loc=0.0, scale=1.0, size=None)

从正态分布(高斯分布)中抽取随机样本。

正态分布的概率密度函数,是De Moivre首次推导得出,并于200年后Gauss和Laplace分别独立推导出。由于它特殊的形状,常被称为钟形曲线

正态分布在自然界中很常见。比如,它描述了受大量微小随机干扰影响的样本的常见分布,并且每个干扰都有自己独特的分布。

Parameters
	loc  [float or array_like of floats]  分布的中值("centre")。
	scale  [float or array_like of floats]  分布的标准差(spread or "width")。
	size [int or tuple of ints, optional]  输出的形式(shape)。如果给定的形式为(m, n, k),那么m*n*k个样本将被提取出来;如果其值为None(default),并且参数loc和scale均为纯量(scalars),则返回一个样本;否则,np.broadcast(loc, scale).size个样本将被提取出来。

Returns
	out  [ndarry or scalar] 从参数化的正态分布中提取样本。

注:官方文档中关于正态分布的内容没有进行翻译。

Examples
从分布中提取样本:

>>> mu, sigma = 0, 0.1    #mean and standard deviation
>>> s = np.random.normal(mu, sigma, 1000)

验证均值和标准差:

>>> abs(mu - np.mean(s)) < 0.01
True
>>> abs(sigma - np.std(s, ddof = 1)) < 0.01
True

绘出样本的直方图和概率密度函数:

>>> import matplotlib.pyplot as plt
>>> count, bins, ignored = plt.hist(s, 30, density=True)
>>> plt.plot(bins, 1/(sigma * np.sqrt(2 * np.pi)) *
 						np.exp( - (bins - mu)**2 / (2 * sigma**2) ),
 						linewidth=2, color='r')
>>> plt.show()

在这里插入图片描述

  • 8
    点赞
  • 23
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值