Drawing floating numbers using [0, 1] from a uniform distribution using numpy

I'm currently trying to deduce floating numbers from a uniform distribution.

Numpy provides the numpy.random.uniform function.

import numpy as np
sample = np.random.uniform (0, 1, size = (N,) + (2,) + (2,) * K)

However, this module generates values ​​in the half-open interval [0, 1).

How to draw floating numbers with [0, 1] from a uniform distribution?

Thank.

+5
source share
4 answers

It doesn’t matter if you draw evenly distributed numbers from (0,1) or [0,1] or [0,1) or (0,1]. Since the probability of getting 0 or 1 is zero.

+3
source

From the standard Python random.uniform documentation :

b a + (b-a) * random().

, , . , 1.0, , , . , numpy.nextafter. .

+2

random_integers . , , . , 1./MAX_INT .

+2

If your software depends on the difference between [0,1)and [0,1], then you should probably roll your own random number generator, perhaps the one listed here , to fit these strict requirements.

0
source

All Articles