megengine.random.uniform

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

Random variable with uniform distribution \(U(low, high)\).

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

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

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

返回

tensor. The random variable with uniform distribution.

返回类型

Return type

实际案例

>>> import megengine.random as rand
>>> x = rand.uniform(size=(2, 2))
>>> x.numpy()   
array([[0.28603864, 0.3156649 ],
       [0.42066026, 0.9805052 ]], dtype=float32)