nlcpy.random.Generator.integers
- Generator.integers(self, low, high=None, size=None, dtype=u'int64', endpoint=False) Returns random integers from *low* (inclusive) to *high* (exclusive), or if endpoint=True, *low* (inclusive) to *high* (inclusive). Replaces :func:`nlcpy.random.randint` (with endpoint=False) and :func:`nlcpy.random.random_integers` (with endpoint=True)
Returns random integers from low (inclusive) to high (exclusive), or if endpoint=True, low (inclusive) to high (inclusive). Replaces
nlcpy.random.randint()
(with endpoint=False) andnlcpy.random.random_integers()
(with endpoint=True)Returns random integers from the “discrete uniform” distribution of the specified dtype. If high is None (the default), then results are from 0 to low.
- Parameters
- lowint
Lowest (signed) integer to be drawn from the distribution (unless
high=None
, in which case this parameter is 0 and this value is used for high).- highint, optional
If provided, one above the largest (signed) integer to be drawn from the distribution (see above for behavior if
high=None
).- sizeint or tuple of ints, optional
Output shape. If the given shape is, e.g.,
(m, n, k)
, thenm * n * k
samples are drawn.- dtypestr or dtype, optional
Desired dtype of the result. All dtypes are determined by their name, i.e., ‘int64’, ‘int’, etc, so byteorder is not available. The default value is ‘nlcpy.int64’.
- endpointbool, optional
If true, sample from the interval
[low, high]
instead of the default[low, high)
. Defaults to False.
- Returns
- outndarray of ints
size-shaped array of random integers from the appropriate distribution.
Note
When using broadcasting with uint64 dtypes, the maximum value (2**64) cannot be represented as a standard integer type. The high array (or low if high is None) must have object dtype, e.g., array([2**64]).
Restriction
If low is neither a scalar nor None : NotImplementedError occurs.
If high is neither a scalar nor None : NotImplementedError occurs.
Examples
>>> import nlcpy as vp >>> rng = vp.random.default_rng() >>> rng.integers(2, size=10) array([1, 0, 0, 0, 1, 1, 0, 0, 1, 0]) # random >>> rng.integers(1, size=10) array([0, 0, 0, 0, 0, 0, 0, 0, 0, 0])
Generate a 2 x 4 array of ints between 0 and 4, inclusive:
>>> rng.integers(5, size=(2, 4)) array([[4, 0, 2, 1], [3, 2, 2, 0]]) # random