Creates a tensor with the same shape and sharding as `self`, filled with random values from a normal distribution with mean 0 and variance 1. You can pass in `dtype` and `device` keyword arguments to control the data type and device of the tensor. Additionally, all other keyword argume
(self, dtype:DTypeLike|None=None, **kwargs)
| 634 | # ***** random functions ***** |
| 635 | |
| 636 | def randn_like(self, dtype:DTypeLike|None=None, **kwargs) -> Tensor: |
| 637 | """ |
| 638 | Creates a tensor with the same shape and sharding as `self`, filled with random values from a normal distribution with mean 0 and variance 1. |
| 639 | |
| 640 | You can pass in `dtype` and `device` keyword arguments to control the data type and device of the tensor. |
| 641 | Additionally, all other keyword arguments are passed to the constructor of the tensor. |
| 642 | |
| 643 | ```python exec="true" source="above" session="tensor" result="python" |
| 644 | t = Tensor.ones(2, 3) |
| 645 | print(Tensor.randn_like(t).numpy()) |
| 646 | ``` |
| 647 | """ |
| 648 | src = self.stack(self).rand_like(**{**kwargs, "dtype": dtypes.float32}) |
| 649 | # https://en.wikipedia.org/wiki/Box%E2%80%93Muller_transform |
| 650 | return src[0].mul(2*math.pi).cos().mul((1 - src[1]).log().mul(-2).sqrt()).cast(dtype or self.dtype) |
| 651 | |
| 652 | @staticmethod |
| 653 | def randn(*shape, dtype:DTypeLike|None=None, **kwargs) -> Tensor: |