# Python: What is a good way to generate a 1D particle field with a gaussian distribution?

If I have N particles how do I assign their x values so that the end result is Gaussian distribution. i.e. particles near the ends are more spread out than particles near the center.

This doesn't randomly sample points, but instead chooses representative points deterministically.

scipy.stats.norm.ppf(np.linspace(0, 1, 1000+2)[1:-1])


NumPy comes with a nifty random library with various distributions, including normal (Gaussian).

From the Numpy documentation:

mu, sigma = 0, 0.1 # mean and standard deviation
s = np.random.normal(mu, sigma, 1000)


which will give you 1000 normally distributed values with mean mu and standard deviation sigma.

• How do I do the same but not for random values, that is, I want a normally distributed set of values but want them to be structured not random. In this way the distance between each particle would be the same on either side of the gaussian bump. – Isopycnal Oscillation Aug 7 '14 at 19:20
• In response to your comment I was going to suggest s = np.hstack((s, -s)) but I think you are actually asking for s = scipy.stats.norm.ppf(np.linspace(0, 1, 1000+2)[1:-1]). – k20 Aug 7 '14 at 22:31
• @k20 Yes that is exactly what I was looking for (the latter). If you put it in the form of an answer I will accept it. – Isopycnal Oscillation Aug 7 '14 at 22:53