-
-
Notifications
You must be signed in to change notification settings - Fork 9.5k
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
DOC: Improve doc for numpy.random.Generator.choice #18223
Conversation
numpy/random/_generator.pyx
Outdated
@@ -665,6 +665,13 @@ cdef class Generator: | |||
array([3,1,0]) # random | |||
>>> #This is equivalent to rng.permutation(np.arange(5))[:3] | |||
|
|||
Generate a uniform random sample from a 2-D array, without | |||
replacement: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would prefer a wording that emphasizes that it chooses along the first axis. This wording can be read to mean that it selects values from all of the elements of the 2D array (i.e. equivalent to choice(x.ravel())
).
>>> rng.choice([[0, 1, 2], [3, 4, 5], [6, 7, 8]], 2, replace=False) | ||
array([[3, 4, 5], | ||
[0, 1, 2]]) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This example is raising a documentation error.
File "build/testenv/lib/python3.7/site-packages/numpy/random/_generator.cpython-37m-darwin.so", line ?, in Generator.choice
Failed example:
rng.choice([[0, 1, 2], [3, 4, 5], [6, 7, 8]], 2, replace=False)
Expected:
array([[3, 4, 5],
[0, 1, 2]])
Got:
array([[6, 7, 8],
[3, 4, 5]])
You need to use a seed to make it repeatable, or add # may vary
to the first output line. Grep to see examples.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, it had occurred to me, but I guess I missed the # random
in the other examples and couldn't find anything about it in the developer documentation. Cheers!
Thanks @SnoopJeDi . |
The summary of
numpy.random.Generator.choice()
suggests that the function is restricted to 1-D inputs, but this is not the case.This PR removes the "1-D" qualifier from the summary and adds an example demonstrating use of this function for sampling from an array of dimension greater than one.