r"""Random variable with uniform distribution :math:`U(low, high)`. Args: low(float): lower range. Default: 0. high(float): upper range. Default: 1. size(Optional[Iterable[int]]): the size of output tensor. Default: None. Returns: Ret
(
self, low: float = 0, high: float = 1, size: Optional[Iterable[int]] = None
)
| 313 | self._device = None |
| 314 | |
| 315 | def uniform( |
| 316 | self, low: float = 0, high: float = 1, size: Optional[Iterable[int]] = None |
| 317 | ): |
| 318 | r"""Random variable with uniform distribution :math:`U(low, high)`. |
| 319 | |
| 320 | Args: |
| 321 | low(float): lower range. Default: 0. |
| 322 | high(float): upper range. Default: 1. |
| 323 | size(Optional[Iterable[int]]): the size of output tensor. Default: None. |
| 324 | |
| 325 | Returns: |
| 326 | Return type: tensor. The random variable with uniform distribution. |
| 327 | |
| 328 | Examples: |
| 329 | >>> import megengine.random as rand |
| 330 | >>> x = rand.uniform(size=(2, 2)) |
| 331 | >>> x.numpy() # doctest: +SKIP |
| 332 | array([[0.28603864, 0.3156649 ], |
| 333 | [0.42066026, 0.9805052 ]], dtype=float32) |
| 334 | """ |
| 335 | _seed = self._seed() if callable(self._seed) else self._seed |
| 336 | return _uniform( |
| 337 | low=low, |
| 338 | high=high, |
| 339 | size=size, |
| 340 | seed=_seed, |
| 341 | device=self._device, |
| 342 | handle=self._handle, |
| 343 | ) |
| 344 | |
| 345 | def normal( |
| 346 | self, mean: float = 0, std: float = 1, size: Optional[Iterable[int]] = None |