megengine.random.uniform

uniform(low=0, high=1, size=None)

服从均匀分布 $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

返回

输出张量

实际案例

import megengine as mge
import megengine.random as rand

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

输出:

[[0.91600335 0.6680226 ]
 [0.2046729  0.2769141 ]]