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)
The np. random. normal function has three primary parameters that control the output: loc , scale , and size .
Use the formula "=NORMINV(RAND(),B2,C2)", where the RAND() function creates your probability, B2 provides your mean and C2 references your standard deviation. You can change B2 and C2 to reference different cells or enter the values into the formula itself.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With