mindspore.ops.UniformReal

class mindspore.ops.UniformReal(seed=0, seed2=0)[source]

Produces random floating-point values, uniformly distributed to the interval [0, 1).

Note

  • Random seed: a set of regular random numbers can be obtained through some complex mathematical algorithms, and the random seed determines the initial value of this random number. If the random seed is the same in two separate calls, the random number generated will not change.

  • Using the Philox algorithm to scramble seed and seed2 to obtain random seed so that the user doesn’t need to worry about which seed is more important.

  • Currently, on the Ascend platform, shape as a Tensor is not supported. This is supported on CPU/GPU platforms. When the input is a Tensor, the supported data types are as follows:

    • GPU: int32, int64.

    • CPU: int16, int32, int64.

Parameters
  • seed (int, optional) – The operator-level random seed, used to generate random numbers, must be non-negative. Default: 0 .

  • seed2 (int, optional) – The global random seed, which combines with the operator-level random seed to determine the final generated random number, must be non-negative. Default: 0 .

Inputs:
  • shape (Union[tuple, Tensor]) - The shape of tensor to be generated. Only constant value is allowed.

Outputs:

Tensor. The shape that the input ‘shape’ denotes. The dtype is float32.

Raises
  • TypeError – If seed or seed2 is not an int.

  • TypeError – If shape is neither a tuple nor a Tensor.

  • ValueError – If shape is not a constant value.

Supported Platforms:

Ascend GPU CPU

Examples

>>> from mindspore import ops
>>> shape = (2, 2)
>>> uniformreal = ops.UniformReal(seed=2)
>>> output = uniformreal(shape)
>>> result = output.shape
>>> print(result)
(2, 2)