megengine.random.RNG.uniform

RNG.uniform(low=0, high=1, size=None)[源代码]

Random variable with uniform distribution $U(0, 1)$.

参数
  • low (float) – lower range. Default: 0

  • high (float) – upper range. Default: 1

  • size (Optional[Iterable[int]]) – the size of output tensor. Default: None

返回

the output tensor.

实际案例

import megengine as mge
import megengine.random as rand

x = rand.uniform(size=(2, 2))
print(x.numpy())

Outputs:

[[0.91600335 0.6680226 ]
 [0.2046729  0.2769141 ]]