np.random.rand vs np.random.random
up vote
13
down vote
favorite
I find Python (and its ecosystem) to be full of strange conventions and inconsistencies and this is another example:
np.random.rand
Create an array of the given shape and populate it with random samples from a uniform distribution over [0, 1).
np.random.random
Return random floats in the half-open interval [0.0, 1.0). Results are from the “continuous uniform” distribution over the stated interval.
??? What exactly is the difference there?
python numpy
|
show 4 more comments
up vote
13
down vote
favorite
I find Python (and its ecosystem) to be full of strange conventions and inconsistencies and this is another example:
np.random.rand
Create an array of the given shape and populate it with random samples from a uniform distribution over [0, 1).
np.random.random
Return random floats in the half-open interval [0.0, 1.0). Results are from the “continuous uniform” distribution over the stated interval.
??? What exactly is the difference there?
python numpy
There is a difference between a "continuous uniform" distribution and a uniform distribution. This could help clarify it for you:docs.scipy.org/doc/numpy-1.13.0/reference/generated/…
– user8502296
Nov 10 '17 at 22:09
1
See stackoverflow.com/a/24542083/6328256
– shash678
Nov 10 '17 at 22:10
See en.wikipedia.org/wiki/Uniform_distribution_(continuous) and en.wikipedia.org/wiki/Discrete_uniform_distribution
– Barmar
Nov 10 '17 at 22:29
This is probably the same case here: stackoverflow.com/a/46634281/2285236
– ayhan
Nov 10 '17 at 22:43
1
@Caleb_McCreary I literally quoted from that page.. and no, there isn't a difference unless they had said "discrete" and "continuous", and discrete doesn't make sense between 0 and 1. Check the answer, the two functions are actually the same, seems like just a convention for matlab users and to confuse/annoy others
– SpaceMonkey
Nov 10 '17 at 22:55
|
show 4 more comments
up vote
13
down vote
favorite
up vote
13
down vote
favorite
I find Python (and its ecosystem) to be full of strange conventions and inconsistencies and this is another example:
np.random.rand
Create an array of the given shape and populate it with random samples from a uniform distribution over [0, 1).
np.random.random
Return random floats in the half-open interval [0.0, 1.0). Results are from the “continuous uniform” distribution over the stated interval.
??? What exactly is the difference there?
python numpy
I find Python (and its ecosystem) to be full of strange conventions and inconsistencies and this is another example:
np.random.rand
Create an array of the given shape and populate it with random samples from a uniform distribution over [0, 1).
np.random.random
Return random floats in the half-open interval [0.0, 1.0). Results are from the “continuous uniform” distribution over the stated interval.
??? What exactly is the difference there?
python numpy
python numpy
asked Nov 10 '17 at 22:05
SpaceMonkey
1,6041840
1,6041840
There is a difference between a "continuous uniform" distribution and a uniform distribution. This could help clarify it for you:docs.scipy.org/doc/numpy-1.13.0/reference/generated/…
– user8502296
Nov 10 '17 at 22:09
1
See stackoverflow.com/a/24542083/6328256
– shash678
Nov 10 '17 at 22:10
See en.wikipedia.org/wiki/Uniform_distribution_(continuous) and en.wikipedia.org/wiki/Discrete_uniform_distribution
– Barmar
Nov 10 '17 at 22:29
This is probably the same case here: stackoverflow.com/a/46634281/2285236
– ayhan
Nov 10 '17 at 22:43
1
@Caleb_McCreary I literally quoted from that page.. and no, there isn't a difference unless they had said "discrete" and "continuous", and discrete doesn't make sense between 0 and 1. Check the answer, the two functions are actually the same, seems like just a convention for matlab users and to confuse/annoy others
– SpaceMonkey
Nov 10 '17 at 22:55
|
show 4 more comments
There is a difference between a "continuous uniform" distribution and a uniform distribution. This could help clarify it for you:docs.scipy.org/doc/numpy-1.13.0/reference/generated/…
– user8502296
Nov 10 '17 at 22:09
1
See stackoverflow.com/a/24542083/6328256
– shash678
Nov 10 '17 at 22:10
See en.wikipedia.org/wiki/Uniform_distribution_(continuous) and en.wikipedia.org/wiki/Discrete_uniform_distribution
– Barmar
Nov 10 '17 at 22:29
This is probably the same case here: stackoverflow.com/a/46634281/2285236
– ayhan
Nov 10 '17 at 22:43
1
@Caleb_McCreary I literally quoted from that page.. and no, there isn't a difference unless they had said "discrete" and "continuous", and discrete doesn't make sense between 0 and 1. Check the answer, the two functions are actually the same, seems like just a convention for matlab users and to confuse/annoy others
– SpaceMonkey
Nov 10 '17 at 22:55
There is a difference between a "continuous uniform" distribution and a uniform distribution. This could help clarify it for you:docs.scipy.org/doc/numpy-1.13.0/reference/generated/…
– user8502296
Nov 10 '17 at 22:09
There is a difference between a "continuous uniform" distribution and a uniform distribution. This could help clarify it for you:docs.scipy.org/doc/numpy-1.13.0/reference/generated/…
– user8502296
Nov 10 '17 at 22:09
1
1
See stackoverflow.com/a/24542083/6328256
– shash678
Nov 10 '17 at 22:10
See stackoverflow.com/a/24542083/6328256
– shash678
Nov 10 '17 at 22:10
See en.wikipedia.org/wiki/Uniform_distribution_(continuous) and en.wikipedia.org/wiki/Discrete_uniform_distribution
– Barmar
Nov 10 '17 at 22:29
See en.wikipedia.org/wiki/Uniform_distribution_(continuous) and en.wikipedia.org/wiki/Discrete_uniform_distribution
– Barmar
Nov 10 '17 at 22:29
This is probably the same case here: stackoverflow.com/a/46634281/2285236
– ayhan
Nov 10 '17 at 22:43
This is probably the same case here: stackoverflow.com/a/46634281/2285236
– ayhan
Nov 10 '17 at 22:43
1
1
@Caleb_McCreary I literally quoted from that page.. and no, there isn't a difference unless they had said "discrete" and "continuous", and discrete doesn't make sense between 0 and 1. Check the answer, the two functions are actually the same, seems like just a convention for matlab users and to confuse/annoy others
– SpaceMonkey
Nov 10 '17 at 22:55
@Caleb_McCreary I literally quoted from that page.. and no, there isn't a difference unless they had said "discrete" and "continuous", and discrete doesn't make sense between 0 and 1. Check the answer, the two functions are actually the same, seems like just a convention for matlab users and to confuse/annoy others
– SpaceMonkey
Nov 10 '17 at 22:55
|
show 4 more comments
1 Answer
1
active
oldest
votes
up vote
9
down vote
accepted
First note that numpy.random.random
is actually an alias for numpy.random.random_sample
. I'll use the latter in the following. (See this question and answer for more aliases.)
Both functions generate samples from the uniform distribution on [0, 1). The only difference is in how the arguments are handled. With numpy.random.rand
, the length of each dimension of the output array is a separate argument. With numpy.random.random_sample
, the shape argument is a single tuple.
For example, to create an array of samples with shape (3, 5), you can write
sample = np.random.rand(3, 5)
or
sample = np.random.random_sample((3, 5))
(Really, that's it.)
right, so there is actually no difference. I wonder why we have two functions with different names that do the same thing.. IMHO they should clean this up.
– SpaceMonkey
Nov 10 '17 at 22:50
There are historical reasons for these, probably related to making the transition to Python+Numpy easier for Matlab programmers (c.f. Matlab'srand
). Cleaning it up might cause more trouble than it is worth, because there is likely a lot of existing code that uses the different versions of the functions.
– Warren Weckesser
Nov 10 '17 at 22:56
4
It does seem like Python's community values "quick hacks cuz it's easy for me" over consistency. The best example of this is the matplotlib's convention to use numbers like "112" to mean (1,1,2) when creating subplots.. anyway, thanks for your answer.
– SpaceMonkey
Nov 10 '17 at 22:58
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
9
down vote
accepted
First note that numpy.random.random
is actually an alias for numpy.random.random_sample
. I'll use the latter in the following. (See this question and answer for more aliases.)
Both functions generate samples from the uniform distribution on [0, 1). The only difference is in how the arguments are handled. With numpy.random.rand
, the length of each dimension of the output array is a separate argument. With numpy.random.random_sample
, the shape argument is a single tuple.
For example, to create an array of samples with shape (3, 5), you can write
sample = np.random.rand(3, 5)
or
sample = np.random.random_sample((3, 5))
(Really, that's it.)
right, so there is actually no difference. I wonder why we have two functions with different names that do the same thing.. IMHO they should clean this up.
– SpaceMonkey
Nov 10 '17 at 22:50
There are historical reasons for these, probably related to making the transition to Python+Numpy easier for Matlab programmers (c.f. Matlab'srand
). Cleaning it up might cause more trouble than it is worth, because there is likely a lot of existing code that uses the different versions of the functions.
– Warren Weckesser
Nov 10 '17 at 22:56
4
It does seem like Python's community values "quick hacks cuz it's easy for me" over consistency. The best example of this is the matplotlib's convention to use numbers like "112" to mean (1,1,2) when creating subplots.. anyway, thanks for your answer.
– SpaceMonkey
Nov 10 '17 at 22:58
add a comment |
up vote
9
down vote
accepted
First note that numpy.random.random
is actually an alias for numpy.random.random_sample
. I'll use the latter in the following. (See this question and answer for more aliases.)
Both functions generate samples from the uniform distribution on [0, 1). The only difference is in how the arguments are handled. With numpy.random.rand
, the length of each dimension of the output array is a separate argument. With numpy.random.random_sample
, the shape argument is a single tuple.
For example, to create an array of samples with shape (3, 5), you can write
sample = np.random.rand(3, 5)
or
sample = np.random.random_sample((3, 5))
(Really, that's it.)
right, so there is actually no difference. I wonder why we have two functions with different names that do the same thing.. IMHO they should clean this up.
– SpaceMonkey
Nov 10 '17 at 22:50
There are historical reasons for these, probably related to making the transition to Python+Numpy easier for Matlab programmers (c.f. Matlab'srand
). Cleaning it up might cause more trouble than it is worth, because there is likely a lot of existing code that uses the different versions of the functions.
– Warren Weckesser
Nov 10 '17 at 22:56
4
It does seem like Python's community values "quick hacks cuz it's easy for me" over consistency. The best example of this is the matplotlib's convention to use numbers like "112" to mean (1,1,2) when creating subplots.. anyway, thanks for your answer.
– SpaceMonkey
Nov 10 '17 at 22:58
add a comment |
up vote
9
down vote
accepted
up vote
9
down vote
accepted
First note that numpy.random.random
is actually an alias for numpy.random.random_sample
. I'll use the latter in the following. (See this question and answer for more aliases.)
Both functions generate samples from the uniform distribution on [0, 1). The only difference is in how the arguments are handled. With numpy.random.rand
, the length of each dimension of the output array is a separate argument. With numpy.random.random_sample
, the shape argument is a single tuple.
For example, to create an array of samples with shape (3, 5), you can write
sample = np.random.rand(3, 5)
or
sample = np.random.random_sample((3, 5))
(Really, that's it.)
First note that numpy.random.random
is actually an alias for numpy.random.random_sample
. I'll use the latter in the following. (See this question and answer for more aliases.)
Both functions generate samples from the uniform distribution on [0, 1). The only difference is in how the arguments are handled. With numpy.random.rand
, the length of each dimension of the output array is a separate argument. With numpy.random.random_sample
, the shape argument is a single tuple.
For example, to create an array of samples with shape (3, 5), you can write
sample = np.random.rand(3, 5)
or
sample = np.random.random_sample((3, 5))
(Really, that's it.)
edited Nov 7 at 22:40
answered Nov 10 '17 at 22:37
Warren Weckesser
66.9k792126
66.9k792126
right, so there is actually no difference. I wonder why we have two functions with different names that do the same thing.. IMHO they should clean this up.
– SpaceMonkey
Nov 10 '17 at 22:50
There are historical reasons for these, probably related to making the transition to Python+Numpy easier for Matlab programmers (c.f. Matlab'srand
). Cleaning it up might cause more trouble than it is worth, because there is likely a lot of existing code that uses the different versions of the functions.
– Warren Weckesser
Nov 10 '17 at 22:56
4
It does seem like Python's community values "quick hacks cuz it's easy for me" over consistency. The best example of this is the matplotlib's convention to use numbers like "112" to mean (1,1,2) when creating subplots.. anyway, thanks for your answer.
– SpaceMonkey
Nov 10 '17 at 22:58
add a comment |
right, so there is actually no difference. I wonder why we have two functions with different names that do the same thing.. IMHO they should clean this up.
– SpaceMonkey
Nov 10 '17 at 22:50
There are historical reasons for these, probably related to making the transition to Python+Numpy easier for Matlab programmers (c.f. Matlab'srand
). Cleaning it up might cause more trouble than it is worth, because there is likely a lot of existing code that uses the different versions of the functions.
– Warren Weckesser
Nov 10 '17 at 22:56
4
It does seem like Python's community values "quick hacks cuz it's easy for me" over consistency. The best example of this is the matplotlib's convention to use numbers like "112" to mean (1,1,2) when creating subplots.. anyway, thanks for your answer.
– SpaceMonkey
Nov 10 '17 at 22:58
right, so there is actually no difference. I wonder why we have two functions with different names that do the same thing.. IMHO they should clean this up.
– SpaceMonkey
Nov 10 '17 at 22:50
right, so there is actually no difference. I wonder why we have two functions with different names that do the same thing.. IMHO they should clean this up.
– SpaceMonkey
Nov 10 '17 at 22:50
There are historical reasons for these, probably related to making the transition to Python+Numpy easier for Matlab programmers (c.f. Matlab's
rand
). Cleaning it up might cause more trouble than it is worth, because there is likely a lot of existing code that uses the different versions of the functions.– Warren Weckesser
Nov 10 '17 at 22:56
There are historical reasons for these, probably related to making the transition to Python+Numpy easier for Matlab programmers (c.f. Matlab's
rand
). Cleaning it up might cause more trouble than it is worth, because there is likely a lot of existing code that uses the different versions of the functions.– Warren Weckesser
Nov 10 '17 at 22:56
4
4
It does seem like Python's community values "quick hacks cuz it's easy for me" over consistency. The best example of this is the matplotlib's convention to use numbers like "112" to mean (1,1,2) when creating subplots.. anyway, thanks for your answer.
– SpaceMonkey
Nov 10 '17 at 22:58
It does seem like Python's community values "quick hacks cuz it's easy for me" over consistency. The best example of this is the matplotlib's convention to use numbers like "112" to mean (1,1,2) when creating subplots.. anyway, thanks for your answer.
– SpaceMonkey
Nov 10 '17 at 22:58
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f47231852%2fnp-random-rand-vs-np-random-random%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
There is a difference between a "continuous uniform" distribution and a uniform distribution. This could help clarify it for you:docs.scipy.org/doc/numpy-1.13.0/reference/generated/…
– user8502296
Nov 10 '17 at 22:09
1
See stackoverflow.com/a/24542083/6328256
– shash678
Nov 10 '17 at 22:10
See en.wikipedia.org/wiki/Uniform_distribution_(continuous) and en.wikipedia.org/wiki/Discrete_uniform_distribution
– Barmar
Nov 10 '17 at 22:29
This is probably the same case here: stackoverflow.com/a/46634281/2285236
– ayhan
Nov 10 '17 at 22:43
1
@Caleb_McCreary I literally quoted from that page.. and no, there isn't a difference unless they had said "discrete" and "continuous", and discrete doesn't make sense between 0 and 1. Check the answer, the two functions are actually the same, seems like just a convention for matlab users and to confuse/annoy others
– SpaceMonkey
Nov 10 '17 at 22:55