flopscope.numpy.random.random_sample
fnp.random.random_sample(size=None)[flopscope source]
Return random floats in the half-open interval [0.0, 1.0).
Adapted from NumPy docs np.random.random_sample
Aliasesfnp.random.ranf, fnp.random.sample
Cost
per-operation
Flopscope Context
Sampling; cost = numel(output).
Results are from the "continuous uniform" distribution over the
stated interval. To sample multiply
the output of random_sample by (b-a) and add a:
(b - a) * random_sample() + aNote.
New code should use the random method of a Generator instance instead; please see the random-quick-start.
Parameters
- size:int or tuple of ints, optional
Output shape. If the given shape is, e.g.,
(m, n, k), thenm * n * ksamples are drawn. Default is None, in which case a single value is returned.
Returns
- out:float or ndarray of floats
Array of random floats of shape size (unless
size=None, in which case a single float is returned).
See also
- we.flops.random.Generator.random which should be used for new code.
Examples
>>> flops.random.random_sample()
0.47108547995356098 # random
>>> type(flops.random.random_sample())
<class 'float'>
>>> flops.random.random_sample((5,))
array([ 0.30220482, 0.86820401, 0.1654503 , 0.11659149, 0.54323428]) # randomThree-by-two array of random numbers from [-5, 0):
>>> 5 * flops.random.random_sample((3, 2)) - 5
array([[-3.99149989, -0.52338984], # random
[-2.99091858, -0.79479508],
[-1.23204345, -1.75224494]])