np.random.uniform documentation incorrect
See original GitHub issueThis is in reference to: http://docs.scipy.org/doc/numpy/reference/generated/numpy.random.uniform.html
Consider this code:
import numpy as np
norm_min = np.zeros(1)
norm_max = np.zeros(1) + 10
print "Input type: {0}.".format(type(norm_min))
norm_init = np.random.uniform(low=norm_min, high=norm_max)
print "Output type: {0}.".format(type(norm_init))
print norm_init.tolist()
The documentation says the return type from this method is an ndarray
, however, if the input arrays are single-element, the result is a float. Either the method is incorrect in returning a float (I believe if you give it a single-element array, that is what it should be returned), or else the documentation should note this.
Yes, this can be fixed with:
norm_init = np.random.uniform(low=norm_min, high=norm_max, size=norm_min.size)
but that does not address the contradiction above.
Issue Analytics
- State:
- Created 10 years ago
- Comments:7 (5 by maintainers)
Top Results From Across the Web
How to Use np.random.uniform - Sharp Sight
This tutorial explains how to use np.random.uniform (Numpy random uniform). It explains the syntax and shows clear examples.
Read more >numpy.random.uniform — NumPy v1.24 Manual
Draw samples from a uniform distribution. Samples are uniformly distributed over the half-open interval [low, high) (includes low, but excludes high) ...
Read more >numpy.random.uniform() in Python - GeeksforGeeks
uniform () method, we can get the random samples from uniform distribution and returns the random samples as numpy array by using this...
Read more >What is the best way of getting random numbers in NumPy?
From the documentation for numpy.random.random_sample : Results are from the “continuous uniform” distribution over the stated interval.
Read more >numpy.random.choice — NumPy v1.9 Manual
If not given the sample assumes a uniform distribution over all entries in a. Returns: samples : 1-D ndarray, shape (size,). The generated...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
This also happens with
np.random.normal
. I’d guess others then too, but haven’t done an exhaustive search.I recommend converting each parameter to a numpy array and returning a scalar iff all of the converted parameters have shape
()
. We should not explicitly check for numpy arrays since someone may pass a list, as in my example above.