2
$\begingroup$

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.

$\endgroup$

2 Answers 2

6
$\begingroup$

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

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

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.

$\endgroup$
3
  • $\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$
    – k20
    Commented 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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.