mygrad.random.ranf#

mygrad.random.ranf(shape: Optional[Shape] = None, *, constant: Optional[bool] = None) Tensor[source]#

Return random floats in the half-open interval [0.0, 1.0).

To create a random sample of a given shape on the interval [a, b), call (b-a) * ranf(shape) + a

Parameters
shape: int or tuple of ints, optional

Output shape. If the given shape is, e.g., (m, n, k), then m * n * k samples are drawn. Default is None, in which case a single value is returned.

constantOptional[bool]

If True, this tensor is treated as a constant, and thus does not facilitate back propagation (i.e. constant.grad will always return None).

Defaults to False for float-type data. Defaults to True for integer-type data.

Integer-type tensors must be constant.

Returns
——-
int or mygrad.Tensor of ints

shape-shaped array of random integers from the appropriate distribution, or a single such random int if size not provided.

Examples

>>> from mygrad.random import ranf
>>> ranf((2, 3, 1))
Tensor([[[0.9343681 ],
         [0.29573802],
         [0.84759669]],
[[0.34563731],

[0.68601617], [0.02388943]]])

>>> ranf()
Tensor(0.77739196)