megengine.random.uniform

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

服从均匀分布 $U(0, 1)$ 的随机变量

参数
  • low (float) – 下界。默认值:0

  • high (float) – 上界。默认值:1

  • size (Optional[Iterable[int]]) – 输出向量的大小。默认值: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 ]]