python– 如何在pytorch中创建正态分布

python– 如何在pytorch中创建正态分布,第1张

概述我想在pytorch中创建一个随机正态分布,mean和std分别为4,0.5.我找不到它的API.有谁知道?非常感谢.最佳答案对于标准正态分布(即mean = 0和variance = 1),您可以使用torch.randn()对于自定义均值和标准的情况,您可以使用torch.distributions.Normal() Init signature:

我想在pytorch中创建一个随机正态分布,mean和std分别为4,0.5.我找不到它的API.有谁知道?非常感谢.最佳答案对于标准正态分布(即mean = 0和variance = 1),您可以使用torch.randn()

对于自定义均值和标准的情况,您可以使用torch.distributions.Normal()

Init signature:
tdist.normal(loc,scale,valIDate_args=None)

Docstring:
Creates a normal (also called Gaussian) distribution parameterized by
loc and scale.

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 tdistIn [33]: n = tdist.normal(torch.tensor([4.0]),torch.tensor([0.5]))In [34]: n.sample((2,))Out[34]: tensor([[ 3.6577],[ 4.7001]])
总结

以上是内存溢出为你收集整理的python – 如何在pytorch中创建正态分布全部内容,希望文章能够帮你解决python – 如何在pytorch中创建正态分布所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/langs/1205989.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-06-04
下一篇 2022-06-04

发表评论

登录后才能评论

评论列表(0条)

保存