-
-
Notifications
You must be signed in to change notification settings - Fork 11k
DOC: Draw more attention to which functions in random are convenience wrappers #13035
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1328,6 +1328,12 @@ cdef class RandomState: | |
|
||
Random values in a given shape. | ||
|
||
.. note:: | ||
This is a convenience function for users porting code from Matlab, | ||
and wraps `numpy.random.random_sample`. That function takes a | ||
tuple to specify the size of the output, which is consistent with | ||
other NumPy functions like `numpy.zeros` and `numpy.ones`. | ||
|
||
Create an array of the given shape and populate it with | ||
random samples from a uniform distribution | ||
over ``[0, 1)``. | ||
|
@@ -1347,12 +1353,6 @@ cdef class RandomState: | |
-------- | ||
random | ||
|
||
Notes | ||
----- | ||
This is a convenience function. If you want an interface that | ||
takes a shape-tuple as the first argument, refer to | ||
np.random.random_sample . | ||
|
||
Examples | ||
-------- | ||
>>> np.random.rand(3,2) | ||
|
@@ -1372,16 +1372,17 @@ cdef class RandomState: | |
|
||
Return a sample (or samples) from the "standard normal" distribution. | ||
|
||
If positive, int_like or int-convertible arguments are provided, | ||
`randn` generates an array of shape ``(d0, d1, ..., dn)``, filled | ||
with random floats sampled from a univariate "normal" (Gaussian) | ||
distribution of mean 0 and variance 1 (if any of the :math:`d_i` are | ||
floats, they are first converted to integers by truncation). A single | ||
float randomly sampled from the distribution is returned if no | ||
argument is provided. | ||
.. note:: | ||
This is a convenience function for users porting code from Matlab, | ||
and wraps `numpy.random.standard_normal`. That function takes a | ||
tuple to specify the size of the output, which is consistent with | ||
other NumPy functions like `numpy.zeros` and `numpy.ones`. | ||
|
||
This is a convenience function. If you want an interface that takes a | ||
tuple as the first argument, use `numpy.random.standard_normal` instead. | ||
If positive int_like arguments are provided, `randn` generates an array | ||
of shape ``(d0, d1, ..., dn)``, filled | ||
with random floats sampled from a univariate "normal" (Gaussian) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Don't need quotes around "normal". There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Inherited from the old docstring |
||
distribution of mean 0 and variance 1. A single float randomly sampled | ||
from the distribution is returned if no argument is provided. | ||
|
||
Parameters | ||
---------- | ||
|
@@ -1399,6 +1400,7 @@ cdef class RandomState: | |
See Also | ||
-------- | ||
standard_normal : Similar, but takes a tuple as its argument. | ||
normal : Also accepts mu and sigma arguments. | ||
|
||
Notes | ||
----- | ||
|
@@ -1409,14 +1411,13 @@ cdef class RandomState: | |
Examples | ||
-------- | ||
>>> np.random.randn() | ||
2.1923875335537315 #random | ||
2.1923875335537315 # random | ||
|
||
Two-by-four array of samples from N(3, 6.25): | ||
|
||
>>> 2.5 * np.random.randn(2, 4) + 3 | ||
array([[-4.49401501, 4.00950034, -1.81814867, 7.29718677], #random | ||
[ 0.39924804, 4.68456316, 4.99394529, 4.84057254]]) #random | ||
|
||
>>> 3 + 2.5 * np.random.randn(2, 4) | ||
array([[-4.49401501, 4.00950034, -1.81814867, 7.29718677], # random | ||
[ 0.39924804, 4.68456316, 4.99394529, 4.84057254]]) # random | ||
""" | ||
if len(args) == 0: | ||
return self.standard_normal() | ||
|
@@ -1536,20 +1537,43 @@ cdef class RandomState: | |
Returns | ||
------- | ||
out : float or ndarray | ||
Drawn samples. | ||
A floating-point array of shape ``size`` of drawn samples, or a | ||
single sample if ``size`` was not specified. | ||
|
||
Notes | ||
----- | ||
For random samples from :math:`N(\\mu, \\sigma^2)`, use one of:: | ||
|
||
mu + sigma * np.random.standard_normal(size=...) | ||
np.random.normal(mu, sigma, size=...) | ||
|
||
See Also | ||
-------- | ||
normal : | ||
Equivalent function with additional ``loc`` and ``scale`` arguments | ||
for setting the mean and standard deviation. | ||
|
||
Examples | ||
-------- | ||
>>> np.random.standard_normal() | ||
2.1923875335537315 #random | ||
|
||
>>> s = np.random.standard_normal(8000) | ||
>>> s | ||
array([ 0.6888893 , 0.78096262, -0.89086505, ..., 0.49876311, #random | ||
-0.38672696, -0.4685006 ]) #random | ||
array([ 0.6888893 , 0.78096262, -0.89086505, ..., 0.49876311, # random | ||
-0.38672696, -0.4685006 ]) # random | ||
>>> s.shape | ||
(8000,) | ||
>>> s = np.random.standard_normal(size=(3, 4, 2)) | ||
>>> s.shape | ||
(3, 4, 2) | ||
|
||
Two-by-four array of samples from :math:`N(3, 6.25)`: | ||
|
||
>>> 3 + 2.5 * np.random.standard_normal(size=(2, 4)) | ||
array([[-4.49401501, 4.00950034, -1.81814867, 7.29718677], # random | ||
[ 0.39924804, 4.68456316, 4.99394529, 4.84057254]]) # random | ||
|
||
""" | ||
return cont0_array(self.internal_state, rk_gauss, size, self.lock) | ||
|
||
|
@@ -1642,6 +1666,12 @@ cdef class RandomState: | |
... linewidth=2, color='r') | ||
>>> plt.show() | ||
|
||
Two-by-four array of samples from N(3, 6.25): | ||
|
||
>>> np.random.normal(3, 2.5, size=(2, 4)) | ||
array([[-4.49401501, 4.00950034, -1.81814867, 7.29718677], # random | ||
[ 0.39924804, 4.68456316, 4.99394529, 4.84057254]]) # random | ||
|
||
""" | ||
cdef ndarray oloc, oscale | ||
cdef double floc, fscale | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Might as well justify the text a bit more.
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.
Makes the diff noisier and the two commits harder to separate, would prefer not to