我想在pytorch中创建一个随机正态分布,mean和std分别为4,0.5.我找不到它的API.有谁知道?非常感谢.
最佳答案
对于标准正态分布(即mean = 0和variance = 1),您可以使用torch.randn()
原文链接:https://www.f2er.com/python/438893.html对于自定义均值和标准的情况,您可以使用torch.distributions.Normal()
Init signature:
tdist.Normal(loc,scale,validate_args=None)Docstring:
Creates a normal (also called Gaussian) distribution parameterized by
loc
andscale
.Args:
loc (float or Tensor): mean of the distribution (often referred to as mu)
scale (float or Tensor): standard deviation of the distribution
(often referred to as sigma)
这是一个例子:
In [32]: import torch.distributions as tdist
In [33]: n = tdist.Normal(torch.tensor([4.0]),torch.tensor([0.5]))
In [34]: n.sample((2,))
Out[34]:
tensor([[ 3.6577],[ 4.7001]])