ustroetz - 1 year ago 172

Python Question

I want to create a normal distributed array with numpy.random.normal that only consists of positive values.

For example the following illustrates that it sometimes gives back negative values and sometimes positive. How can I modify it so it will only gives back positive values?

`>>> import numpy`

>>> numpy.random.normal(10,8,3)

array([ -4.98781629, 20.12995344, 4.7284051 ])

>>> numpy.random.normal(10,8,3)

array([ 17.71918829, 15.97617052, 1.2328115 ])

>>>

I guess I could solve it somehow like this:

`myList = numpy.random.normal(10,8,3)`

while item in myList <0:

# run again until all items are positive values

myList = numpy.random.normal(10,8,3)

Recommended for you: Get network issues from **WhatsUp Gold**. **Not end users.**

Answer Source

The normal distribution, by definition, extends from -inf to +inf so what you are asking for doesn't make sense mathematically.

You can take a normal distribution and take the absolute value to "clip" to positive values, or just discard negative values, but you should understand that it will no longer be a normal distribution.

Recommended from our users: **Dynamic Network Monitoring from WhatsUp Gold from IPSwitch**. ** Free Download**