mygrad.random.random#

mygrad.random.random(shape: Shape | None = None, *, constant: bool | None = 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) * random(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 random
>>> random((2, 4))
Tensor([[0.14928578, 0.28812813, 0.56885892, 0.49555962],
        [0.19780163, 0.51162365, 0.7849505 , 0.47864586]])