torch.normal
时间: 2023-10-05 10:14:01 浏览: 115
torch.normal is a PyTorch function that generates a tensor of random numbers from a normal distribution with a mean and standard deviation specified by the user.
The syntax for torch.normal is as follows:
torch.normal(mean, std, out=None)
- mean: the mean of the normal distribution. This can be a scalar or a tensor with the same shape as the desired output tensor.
- std: the standard deviation of the normal distribution. This can be a scalar or a tensor with the same shape as the desired output tensor.
- out (optional): the output tensor. If provided, the random numbers will be generated into this tensor rather than a new one.
Example usage:
```python
import torch
# Generate a tensor of size (3, 4) with random numbers from a normal distribution
# with mean 0 and standard deviation 1
x = torch.normal(0, 1, size=(3, 4))
print(x)
```
Output:
```
tensor([[-1.0262, -0.7695, 0.1677, -0.0408],
[-1.2485, -1.4555, 0.2709, 0.2705],
[-1.6543, -1.0819, 1.0578, -0.3285]])
```
阅读全文