1.torch.rand()函数
均匀分布
torch.rand(*sizes, out=None) → Tensor
返回一个张量,包含了从区间[0, 1)的均匀分布中抽取的一组随机数。张量的形状由参数sizes定义。
参数:
sizes (int...) - 整数序列,定义了输出张量的形状
out (Tensor, optinal) - 结果张量
print(torch.rand(1, 5)) # 1行5列
输出:
tensor([[0.0975, 0.9950, 0.9687, 0.8556, 0.3420]])
2.torch.randn()
torch.randn(*sizes, out=None) → Tensor
返回一个张量,包含了从标准正态分布(均值为0,方差为1,即高斯白噪声)中抽取的一组随机数。张量的形状由参数sizes定义。
参数:
sizes (int...) - 整数序列,定义了输出张量的形状
out (Tensor, optinal) - 结果张量
print(torch.randn(1,5))
输出:
tensor([[ 1.5800, 0.4972, 0.3574, -0.1394, -0.6761]])
参考链接:https://blog.csdn.net/wangwangstone/article/details/89815661
原文:https://www.cnblogs.com/shuangcao/p/12864623.html