mygrad.random.sample#
- mygrad.random.sample(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) * sample(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 returnNone
).Defaults to
False
for float-type data. Defaults toTrue
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 sample >>> sample((3, 4)) Tensor([[0.47263933, 0.10928814, 0.19737707, 0.30879006], [0.49870689, 0.05849937, 0.21095352, 0.09778017], [0.405788 , 0.91888808, 0.15061143, 0.63140668]])
>>> sample() Tensor(0.50690423)