nlcpy.random.RandomState.uniform
- RandomState.uniform(self, low=0.0, high=1.0, size=None)
Draws samples from a uniform distribution.
Samples are uniformly distributed over the half-open interval
[low, high)
(includes low, but excludes high). In other words, any value within the given interval is equally likely to be drawn by uniform.- Parameters
- lowfloat, optional
Lower boundary of the output interval. All values generated will be greater than or equal to low. The default value is 0.
- highfloat
Upper boundary of the output interval. All values generated will be less than high. The default value is 1.0.
- sizeint or tuple of ints, optional
Output shape. If the given shape is, e.g.,
(m, n, k)
, thenm * n * k
samples are drawn.
- Returns
- outndarray
Drawn samples from the parameterized uniform distribution.
See also
RandomState.randint
Returns random integers from low (inclusive) to high (exclusive).
RandomState.random_integers
Random integers of type vp.int between low and high, inclusive.
RandomState.random_sample
Returns random floats in the half-open interval
[0.0, 1.0)
.RandomState.random
Returns random floats in the half-open interval
[0.0, 1.0)
.RandomState.rand
Random values in a given shape.
Note
The probability density function of the uniform distribution is
anywhere within the interval
[a, b)
, and zero elsewhere. Whenhigh
==low
, values oflow
will be returned.Restriction
If low is neither a scalar nor None : NotImplementedError occurs.
If high is neither a scalar nor None : NotImplementedError occurs.
Examples
Draw samples from the distribution:
>>> import nlcpy as vp >>> s = vp.random.uniform(-1,0,1000)
All values are within the given interval:
>>> vp.all(s >= -1) array(True) >>> vp.all(s < 0) array(True)
Display the histogram of the samples, along with the probability density function:
>>> import matplotlib.pyplot as plt >>> count, bins, ignored = plt.hist(s.get(), 15, density=True) >>> plt.plot(bins, vp.ones_like(bins), ... linewidth=2, color='r') >>> plt.show()