# Drawing floating numbers with [0, 1] from uniform distribution by using numpy

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

The Numpy provides numpy.random.uniform.

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


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

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

Thanks.

• This question is better posted on StackOverflow. – Peter Flom - Reinstate Monica Feb 17 '13 at 14:31
• Really, mathematically speaking the difference disappears. You'll likely never draw a 0 using np.random.uniform anyways. Not will you ever draw a $1/\pi$, nor a $1/2$, nor a .... – Cam.Davidson.Pilon Feb 17 '13 at 15:41
• What is the reason you'd like to draw a 1? It sounds like maybe a Uniform distribution is maybe not the correct distribution to be using. – Cam.Davidson.Pilon Feb 17 '13 at 15:42
• @Cam makes two very pertinent comments. Please add some clarification about the actual problem you're trying to solve, since we're likely to be able to help you and you're less likely to walk away with a hack that answers the question here but doesn't translate into an applicable solution. There are instances where one needs to guard against a 0 or 1 for numerical reasons, but this doesn't sound on the surface like one of them. Cheers. – cardinal Feb 17 '13 at 21:28
• NB to other readers. As @Cam intimates, there is, most likely, a statistical issue that needs to be addressed here. I'd like to encourage a little patience as we wait for the OP to respond before casting the final vote to close this question. – cardinal Feb 17 '13 at 21:35