nlcpy.random.Generator.uniform¶
-
Generator.
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.
参考
Generator.integers
Returns random integers.
Generator.random
Returns random floats.
注釈
The probability density function of the uniform distribution is
\[p(x) = \frac{1}{b - a}\]anywhere within the interval
[a, b)
, and zero elsewhere.When
high
==low
, values oflow
will be returned.制限事項
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.default_rng().uniform(-1,0,1000)
All values are within the given interval:
>>> vp.all(s >= -1) array(True) >>> vp.all(s < 0) array(True)
>>> 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()