If you're looking for the Truncated normal distribution, SciPy has a function for it called truncnorm
The standard form of this distribution is a standard normal truncated
to the range [a, b] — notice that a and b are defined over the domain
of the standard normal. To convert clip values for a specific mean and
standard deviation, use:
a, b = (myclip_a - my_mean) / my_std, (myclip_b - my_mean) / my_std
truncnorm takes a and b as shape parameters.
>>> from scipy.stats import truncnorm
>>> truncnorm(a=-2/3., b=2/3., scale=3).rvs(size=10)
array([-1.83136675, 0.77599978, -0.01276925, 1.87043384, 1.25024188,
0.59336279, -0.39343176, 1.9449987 , -1.97674358, -0.31944247])
The above example is bounded by -2 and 2 and returns 10 random variates (using the .rvs()
method)
>>> min(truncnorm(a=-2/3., b=2/3., scale=3).rvs(size=10000))
-1.9996074381484044
>>> max(truncnorm(a=-2/3., b=2/3., scale=3).rvs(size=10000))
1.9998486576228549
Here's a histogram plot for -6, 6: