mindspore.Tensor.uniform

Tensor.uniform(from_=0.0, to=1.0, generator=None)[source]

Generates random numbers in the half-open interval [from_, to).

Parameters
  • from (number) – The lower bound of the interval.

  • to (number) – The upper bound of the interval.

  • 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)