np.random.random vs np.random.rand
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))
Read this: What is the difference between single and double bracket Numpy array?