Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Machine Learning by (19k points)

In machine learning tasks. We should get a group of random w.r.t normal distribution with a bound. We can get a normal distribution number with np.random.normal() but it doesn't offer any bound parameter. I want to know how to do that?

1 Answer

0 votes
by (33.1k points)

It is quite complex to parametrize the truncnorm class. Here is an example that would help you to do so:

For example:

from scipy.stats import truncnorm

def get_truncated_normal(mean=0, sd=1, low=0, upp=10):

    return truncnorm(

        (low - mean) / sd, (upp - mean) / sd, loc=mean, scale=sd)

Hope this answer helps.

Browse Categories

...