mygrad.random.rand#

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

Create a Tensor of the given shape and populate it with random samples from a uniform distribution over [0, 1).

Parameters
shape: d0, d1, … dnint, optional

The dimensions of the returned array, must be non-negative. If no argument is given a single Python float 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
mygrad.Tensor

A shape–shaped Tensor of floating-point samples from the uniform distribution over [0, 1), or a single such float if no parameters were supplied.

Examples

>>> from mygrad.random import rand
>>> rand(3,4)
Tensor([[0.9805903 , 0.82640985, 0.88230632, 0.73099815],
        [0.24845968, 0.12532893, 0.63171607, 0.32543228],
        [0.66029533, 0.79285341, 0.54967228, 0.25178508]])