Plotting of 1-dimensional Gaussian distribution function

后端 未结 5 426
忘掉有多难
忘掉有多难 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:31

    In addition to previous answers, I recommend to first calculate the ratio in the exponent, then taking the square:

    def gaussian(x,x0,sigma):
      return np.exp(-np.power((x - x0)/sigma, 2.)/2.)
    

    That way, you can also calculate the gaussian of very small or very large numbers:

    In: gaussian(1e-12,5e-12,3e-12)
    Out: 0.64118038842995462
    

提交回复
热议问题