-
-
Notifications
You must be signed in to change notification settings - Fork 10.9k
random_sample for type float32 #3155
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
In the meantime, you can do the following:
|
Thanks rKern Can someone take up extending the current interface? While we are in there though, why don't the random functions provide an optional out argument in which to pass an allocated buffer? I would be willing to put in some work to do it if an extended api can be agreed upon by the group?
|
The following adds support for strings in the Codeimport numpy as np
def random_sample(size=None, dtype=np.float64):
if type(dtype) == str:
dtype = np.dtype(dtype).type
type_max = 1 << np.finfo(dtype).nmant
sample = np.empty(size, dtype=dtype)
sample[...] = np.random.randint(0, type_max, size=size) / dtype(type_max)
if size is None:
sample = sample[()]
return sample Example Usage
Similar To
|
xref #13163 . This is fixed in the randomgen branch. |
Closing, the new API supports dtype, note the name is now |
Hi Numpy
I need a numpy.float32 array with a distribution between [0...1). I can not find a way to generate this array using the existing numpy.random tools as converting from the default double to float causes the distribution to change to [0..1].
You can see the problem in the code below. Can you suggest a better approach or should an optional argument for dtype be added to the existing methods?
Thanks
David
The text was updated successfully, but these errors were encountered: