如何在 pytorch 中制作截断的正态分布?

How to make a Truncated normal distribution in pytorch?

我想在 PyTorch 中创建一个截断正态分布(即具有范围的高斯分布)。
我希望能够更改均值、标准差和范围。
有 PyTorch 方法吗?

使用torch.nn.init.trunc_normal_.

给定的描述 Here

Fills the input Tensor with values drawn from a truncated normal distribution. The values are effectively drawn from the normal distribution :math:\mathcal{N}(\text{mean}, \text{std}^2) with values outside :math:[a, b] redrawn until they are within the bounds. The method used for generating the random values works best when :math:a \leq \text{mean} \leq b.