Search code examples
pythonplotnormal-distribution

how to make up a 2D feature following a Gaussian distribution, given the mean and standard deviation?


I'm stack in trying to plot a two-dimensional feature which has a mean of [2, 3] and standard deviation [0.4, 1.5], along the x and y axis, respectively.

Any idea?


Solution

  • Use numpy.random.normal to generate N samples from a gaussian distribution, e.g.:

    import numpy as np
    
    xs = np.random.normal(loc=2, scale=0.4, size=100)
    ys = np.random.normal(loc=3, scale=1.5, size=100)
    

    As you might have guessed, loc corresponds to the mean, and scale to the standard deviation.