本文介绍了如何在pytorch中创建正态分布的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

我想在pytorch中创建随机正态分布,均值和标准差分别为4、0.5.我没有找到适用的API.有谁知道?非常感谢.

I want to create a random normal distribution in pytorch and mean and std are 4, 0.5 respectively. I didn't find a API for it. Anyone knows? Thanks very much.

推荐答案

您可以轻松使用 torch.Tensor.normal_()方法.

让我们创建一个尺寸为 1×5 的矩阵Z(一维张量),其中填充了由 mean = 4 std = 0.5 .

Let's create a matrix Z (a 1d tensor) of dimension 1 × 5, filled with random elements samples from the normal distribution parameterized by mean = 4 and std = 0.5.

torch.empty(5).normal_(mean=4,std=0.5)

结果:

tensor([4.1450, 4.0104, 4.0228, 4.4689, 3.7810])

这篇关于如何在pytorch中创建正态分布的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-07 15:46