Creates a tensor with the given shape, filled with random values from a uniform distribution over the interval `[low, high)`. Requires `low < high`. You can pass in `dtype` and `device` keyword arguments to control the data type and device of the tensor. Additionally, all other key
(*shape, low=0.0, high=1.0, dtype:DTypeLike|None=None, **kwargs)
| 703 | |
| 704 | @staticmethod |
| 705 | def uniform(*shape, low=0.0, high=1.0, dtype:DTypeLike|None=None, **kwargs) -> Tensor: |
| 706 | """ |
| 707 | Creates a tensor with the given shape, filled with random values from a uniform distribution over the interval `[low, high)`. |
| 708 | Requires `low < high`. |
| 709 | |
| 710 | You can pass in `dtype` and `device` keyword arguments to control the data type and device of the tensor. |
| 711 | Additionally, all other keyword arguments are passed to the constructor of the tensor. |
| 712 | |
| 713 | ```python exec="true" source="above" session="tensor" result="python" |
| 714 | Tensor.manual_seed(42) |
| 715 | print(Tensor.uniform(2, 3, low=2, high=10).numpy()) |
| 716 | ``` |
| 717 | """ |
| 718 | if not all_int(shape:=argfix(*shape)) or not all(s >= 0 for s in shape): raise ValueError(f"invalid input {shape=}") |
| 719 | if low >= high: raise ValueError(f"Tensor.uniform requires low < high, got {low=}, {high=}") |
| 720 | return ((high-low) * Tensor.rand(*shape, **kwargs)).cast(dtype or dtypes.default_float) + low |
| 721 | |
| 722 | @staticmethod |
| 723 | def scaled_uniform(*shape, **kwargs) -> Tensor: |