Search code examples
pythonpython-3.xnumpymathgaussian

Gaussian distribution in python


I have two columns (2x10) of data the first column is the data the second is the errors. I want to generate the gaussian distribution value for each value in first column taking it with corresponding errors. So how can I manage that?


Solution

  • Try this

    # Your array of data and measurements
    measurements = np.ones((10,2))
    # 10 values drawn from a Gaussian distribution
    measurements[:,1] = np.random.normal(0.0,1.0,size=(10,1))
    

    Where np.random.normal(0.0, 1.0, 1) draws a single value from a Gaussian distribution with a mean of 0 and a standard deviation of 1.0. See the docs for more information.

    The third argument in my code above, denoted by size, gives you the shape of the array of samples you require.