torch.rand()
参考:https://pytorch.org/docs/stable/torch.html#torch.rand
*torch.rand(size, out=None, dtype=None, layout=torch.strided, device=None, requires_grad=False) → Tensor
返回在区间[0,1)[0,1)上由均匀分布的随机数填充的张量
张量的形状由可变参数大小来定义。

example
>>> torch.rand(4)
tensor([ 0.5204, 0.2503, 0.3525, 0.5673])
>>> torch.rand(2, 3)
tensor([[ 0.8237, 0.5781, 0.6879],
[ 0.3816, 0.7249, 0.0998]])
torch.rand_like()
参考:https://pytorch.org/docs/stable/torch.html#torch.rand_like
torch.rand_like(input, dtype=None, layout=None, device=None, requires_grad=False, memory_format=torch.preserve_format) → Tensor
返回与输入相同大小的张量,该张量由区间[0,1)上均匀分布的随机数填充。rand_like(input)相当于torch.rand(input.size(), dtype=input.dtype, layout=input.layout, device=input.device)。
torch.randn()
参考:https://pytorch.org/docs/stable/torch.html#torch.randn
*torch.randn(size, out=None, dtype=None, layout=torch.strided, device=None, requires_grad=False) → Tensor
返回一个从均值为0、方差为1的正态分布(也称为标准正态分布)中填充随机数的张量, outi∼N(0,1)out_i ∼N(0,1)outi∼N(0,1).
张量的形状由可变参数size来定义

example
>>> torch.randn(4)
tensor([-2.1436, 0.9966, 2.3426, -0.6366])
>>> torch.randn(2, 3)
tensor([[ 1.5954, 2.8929, -1.0923],
[ 1.1719, -0.4709, -0.1996]])
torch.randint()
返回一个填满随机整数的张量,这些整数均匀地在低(含)和高(不含)之间生成。张量的形状由可变参数大小来定义。
PyTorch中torch.rand与torch.randn的区别详解
本文详细介绍了PyTorch中torch.rand()、torch.rand_like()、torch.randn()以及torch.randint()的使用。torch.rand()返回[0,1)区间内均匀分布的张量,torch.rand_like()生成与输入张量同样大小且包含[0,1)范围内随机数的张量。torch.randn()则生成符合标准正态分布的张量,而torch.randint()用于生成指定范围内的随机整数张量。"
50329517,5145165,IScroll5实践:上拉加载与下拉刷新,"['前端开发', 'JavaScript', '滚动库', '用户交互', '网页优化']
1421

被折叠的 条评论
为什么被折叠?



