[SOLVED] sampling random floats on a range in numpy

Issue

How can I sample random floats on an interval [a, b] in numpy? Not just integers, but any real numbers. For example,

random_float(5, 10)

would return random numbers between [5, 10]. thanks.

Solution

The uniform distribution would probably do what you are asking.

np.random.uniform(5,10) # A single value
np.random.uniform(5,10,[2,3]) # A 2x3 array

Answered By – Ken

Answer Checked By – Mary Flores (BugsFixing Volunteer)

Leave a Reply

Your email address will not be published. Required fields are marked *