mindspore.Tensor.uniform
- Tensor.uniform(from_=0., to=1., generator=None)[source]
Generates random numbers that follows a uniform distribution within the half-open interval \([from\_, to)\).
\[P(x) = \frac{1}{to - from\_}\]- Parameters
from_ (number, optional) – The lower bound of the interval. Default:
0..to (number, optional) – The upper bound of the interval. Default:
1..generator (Generator, optional) – The random seed. Default:
None.
- Returns
Tensor, with the same shape as tensor.
- Raises
TypeError – If from_ is larger than to.
- Supported Platforms:
Ascend
Examples
>>> import mindspore >>> x = mindspore.ops.ones((4, 2)) >>> generator = mindspore.Generator() >>> generator.manual_seed(100) >>> output = x.uniform(1., 2., generator) >>> print(output.shape) (4, 2)