Plotting of 1-dimensional Gaussian distribution function

后端 未结 5 486
忘掉有多难
忘掉有多难 2021-02-04 01:09

How do I make plots of a 1-dimensional Gaussian distribution function using the mean and standard deviation parameter values (μ, σ) = (−1, 1), (0, 2), and (2, 3)?

I\'m n

5条回答
  •  甜味超标
    2021-02-04 01:28

    You are missing a parantheses in the denominator of your gaussian() function. As it is right now you divide by 2 and multiply with the variance (sig^2). But that is not true and as you can see of your plots the greater variance the more narrow the gaussian is - which is wrong, it should be opposit.

    So just change the gaussian() function to:

    def gaussian(x, mu, sig):
        return np.exp(-np.power(x - mu, 2.) / (2 * np.power(sig, 2.)))
    

提交回复
热议问题