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.
2 Answers
$\begingroup$
$\endgroup$
This doesn't randomly sample points, but instead chooses representative points deterministically.
scipy.stats.norm.ppf(np.linspace(0, 1, 1000+2)[1:-1])
$\begingroup$
$\endgroup$
3
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.
-
$\begingroup$ 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. $\endgroup$ Commented Aug 7, 2014 at 19:20
-
$\begingroup$ 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]). $\endgroup$– k20Commented Aug 7, 2014 at 22:31
-
$\begingroup$ @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. $\endgroup$ Commented Aug 7, 2014 at 22:53