0
$\begingroup$

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.

$\endgroup$
  • 2
    $\begingroup$ This question is better posted on StackOverflow. $\endgroup$ – Peter Flom - Reinstate Monica Feb 17 '13 at 14:31
  • 5
    $\begingroup$ 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 .... $\endgroup$ – Cam.Davidson.Pilon Feb 17 '13 at 15:41
  • 3
    $\begingroup$ 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. $\endgroup$ – Cam.Davidson.Pilon Feb 17 '13 at 15:42
  • 1
    $\begingroup$ @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. $\endgroup$ – cardinal Feb 17 '13 at 21:28
  • 1
    $\begingroup$ 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. $\endgroup$ – cardinal Feb 17 '13 at 21:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.