question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

np.random.uniform documentation incorrect

See original GitHub issue

This 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:closed
  • Created 10 years ago
  • Comments:7 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
demitricommented, Feb 6, 2014

This also happens with np.random.normal. I’d guess others then too, but haven’t done an exhaustive search.

0reactions
rkerncommented, Feb 6, 2014

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found