mindspore.numpy.rand

mindspore.numpy.rand(*shape, dtype=mstype.float32)[源代码]

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

参数
  • *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.

返回

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

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

  • ValueError – If dtype is not float type.

Supported Platforms:

Ascend GPU CPU

样例

>>> 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]]