mindspore.numpy.rand

View Source On Gitee
mindspore.numpy.rand(*shape, dtype=mstype.float32)[source]

Returns a new Tensor with given shape and dtype, filled with random numbers from the uniform distribution on the interval \([0, 1)\).

Parameters
  • *shape (Union[int, tuple(int), list(int)]) – Shape of the new tensor, e.g., \((2, 3)\) or \(2\).

  • dtype (Union[mindspore.dtype, str], optional) – Designated tensor dtype, it must be float type. Default is mindspore.float32.

Returns

Tensor, with the designated shape and dtype, filled with random numbers from the uniform distribution on the interval \([0, 1)\).

Raises
  • TypeError – If input arguments have types not specified above.

  • ValueError – If dtype is not float type.

Supported Platforms:

Ascend GPU CPU

Examples

>>> import mindspore.numpy as np
>>> from mindspore import set_seed
>>> set_seed(1)
>>> print(np.rand((2,3)))
[[4.1702199e-01 9.9718481e-01 7.2032452e-01]
[9.3255734e-01 1.1438108e-04 1.2812445e-01]]