# tensorplay.functional.normal Source: https://www.tensorplay.cn/docs/generated/tensorplay.functional.normal.html ```python tensorplay.functional.normal(mean, std, *, generator=None, out=None) → Tensor ``` Returns a tensor of random numbers drawn from separate normal distributions whose mean and standard deviation are given. The [mean](/docs/generated/tensorplay.functional.mean.html#tensorplay.functional.mean) is a tensor with the mean of each output element’s normal distribution The [std](/docs/generated/tensorplay.functional.std.html#tensorplay.functional.std) is a tensor with the standard deviation of each output element’s normal distribution The shapes of [mean](/docs/generated/tensorplay.functional.mean.html#tensorplay.functional.mean) and [std](/docs/generated/tensorplay.functional.std.html#tensorplay.functional.std) don’t need to match, but the total number of elements in each tensor need to be the same. > **Note** > > When the shapes do not match, the shape of mean is used as the shape for the returned output tensor > **Note** > > When std is a CUDA tensor, this function synchronizes its device with the CPU. Parameters: - mean ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor)) – the tensor of per-element means - std ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor)) – the tensor of per-element standard deviations Keyword Arguments: - generator ([tensorplay.Generator](/docs/generated/tensorplay.Generator.html#tensorplay.Generator), optional) – a pseudorandom number generator for sampling - out ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor), optional) – the output tensor. Example: ``` >>> tensorplay.normal(mean=tensorplay.arange(1., 11.), std=tensorplay.arange(1, 0, -0.1)) tensor([ 1.0425, 3.5672, 2.7969, 4.2925, 4.7229, 6.2134, 8.0505, 8.1408, 9.0563, 10.0566]) ``` ```python tensorplay.functional.normal(mean=0.0, std, *, out=None) → Tensor ``` Similar to the function above, but the means are shared among all drawn elements. Parameters: - mean ([float](https://docs.python.org/3/builtins/functions.html#float), optional) – the mean for all distributions - std ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor)) – the tensor of per-element standard deviations Keyword Arguments: out ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor), optional) – the output tensor. Example: ``` >>> tensorplay.normal(mean=0.5, std=tensorplay.arange(1., 6.)) tensor([-1.2793, -1.0732, -2.0687, 5.1177, -1.2303]) ``` ```python tensorplay.functional.normal(mean, std=1.0, *, out=None) → Tensor ``` Similar to the function above, but the standard deviations are shared among all drawn elements. Parameters: - mean ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor)) – the tensor of per-element means - std ([float](https://docs.python.org/3/builtins/functions.html#float), optional) – the standard deviation for all distributions Keyword Arguments: out ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor), optional) – the output tensor Example: ``` >>> tensorplay.normal(mean=tensorplay.arange(1., 6.)) tensor([ 1.1552, 2.6148, 2.6535, 5.8318, 4.2361]) ``` ```python tensorplay.functional.normal(mean, std, size, *, out=None) → Tensor ``` Similar to the function above, but the means and standard deviations are shared among all drawn elements. The resulting tensor has size given by size. Parameters: - mean ([float](https://docs.python.org/3/builtins/functions.html#float)) – the mean for all distributions - std ([float](https://docs.python.org/3/builtins/functions.html#float)) – the standard deviation for all distributions - size ([int](https://docs.python.org/3/builtins/functions.html#int)...) – a sequence of integers defining the shape of the output tensor. Keyword Arguments: out ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor), optional) – the output tensor. Example: ``` >>> tensorplay.normal(2, 3, size=(1, 4)) tensor([[-1.3987, -1.9544, 3.6048, 0.7909]]) ```