MCPcopy
hub / github.com/tinygrad/tinygrad / normal

Method normal

tinygrad/tensor.py:688–702  ·  view source on GitHub ↗

Creates a tensor with the given shape, filled with random values from a normal distribution with the given `mean` and standard deviation `std`. Requires `std >= 0`. You can pass in `dtype` and `device` keyword arguments to control the data type and device of the tensor. Additionall

(*shape, mean=0.0, std=1.0, **kwargs)

Source from the content-addressed store, hash-verified

686
687 @staticmethod
688 def normal(*shape, mean=0.0, std=1.0, **kwargs) -> Tensor:
689 """
690 Creates a tensor with the given shape, filled with random values from a normal distribution with the given `mean` and standard deviation `std`.
691 Requires `std >= 0`.
692
693 You can pass in `dtype` and `device` keyword arguments to control the data type and device of the tensor.
694 Additionally, all other keyword arguments are passed to the constructor of the tensor.
695
696 ```python exec="true" source="above" session="tensor" result="python"
697 Tensor.manual_seed(42)
698 print(Tensor.normal(2, 3, mean=10, std=2).numpy())
699 ```
700 """
701 if std < 0: raise ValueError(f"Tensor.normal requires std >= 0, got {std=}")
702 return std * Tensor.randn(*shape, **kwargs) + mean
703
704 @staticmethod
705 def uniform(*shape, low=0.0, high=1.0, dtype:DTypeLike|None=None, **kwargs) -> Tensor:

Callers 14

kaiming_normalMethod · 0.80
randomsFunction · 0.80
backend.pyFile · 0.80
gaussian_noiseFunction · 0.80
test_normalMethod · 0.80
test_nll_loss_weightMethod · 0.80
test_dtype_str_argMethod · 0.80
__call__Method · 0.80
__init__Method · 0.80
__init__Method · 0.80

Calls 1

randnMethod · 0.80

Tested by 4

test_normalMethod · 0.64
test_nll_loss_weightMethod · 0.64
test_dtype_str_argMethod · 0.64