zoukankan      html  css  js  c++  java
  • #np.random.normal,产生制定分布的数集(默认是标准正态分布)

    http://docs.scipy.org/doc/numpy/reference/generated/numpy.random.normal.html

    #np.random.normal,产生制定分布的数集
    #http://docs.scipy.org/doc/numpy/reference/generated/numpy.random.normal.html
    # mean and standard deviation
    # 均值的物理意义mu,Mean (“centre”) of the distribution.
    # 方差的物理意义sigma,Standard deviation (spread or “width”) of the distribution
    import numpy as np

    mu, sigma = 0, 0.1
    s = np.random.normal(mu, sigma, 1000)

    #验证均值和方差,是否和随机生成的一样
    print(abs(mu - np.mean(s)) < 0.01)
    print(abs(sigma - np.std(s, ddof=1)) < 0.01) #ddof不知道什么意思


    import matplotlib.pyplot as plt

    count, bins, ignored = plt.hist(s, 10, normed=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()

    numpy.random.normal

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

    Draw random samples from a normal (Gaussian) distribution.

    The probability density function of the normal distribution, first derived by De Moivre and 200 years later by both Gauss and Laplace independently [R250], is often called the bell curve because of its characteristic shape (see the example below).

    The normal distributions occurs often in nature. For example, it describes the commonly occurring distribution of samples influenced by a large number of tiny, random disturbances, each with its own unique distribution [R250].

    Parameters:

    loc : float

    Mean (“centre”) of the distribution.

    scale : float

    Standard deviation (spread or “width”) of the distribution.

    size : int or tuple of ints, optional

    Output shape. If the given shape is, e.g., (m, n, k), then m * n * k samples are drawn. Default is None, in which case a single value is returned.

  • 相关阅读:
    牛客小白月赛16E
    洛谷P1309 瑞士轮
    洛谷P1781 宇宙总统
    洛谷P1068 分数线划定
    洛谷P1059 明明的随机数(桶排思想)
    洛谷P1177 【模板】快速排序 (归并排序)
    Python基础-----sys模块
    Python基础-----模块导入注意事项
    Python基础-----os模块
    Python基础-----random随机模块(验证码)
  • 原文地址:https://www.cnblogs.com/qqhfeng/p/5336293.html
Copyright © 2011-2022 走看看