Skip to content
Advertisement

Strictly positive values in normal distribution in Python

Is it possible to define a strictly positive range for normal distribution like I want to have a distribution in the range (0,10) with a certain mu, sigma?

Using np.random.normal, sometimes I get negative values which I don’t want.

import numpy as np
I=np.random.normal(3, 10, size=(3,3))

Advertisement

Answer

You should try ‘scipy.stats.truncnorm’ – quote The standard form of this distribution is a standard normal truncated to the range

https://docs.scipy.org/doc/scipy/reference/generated/scipy.stats.truncnorm.html

User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement