第一句子网 - 唯美句子、句子迷、好句子大全
第一句子网 > 【PyTorch】rand/randn/randint/randperm的区别

【PyTorch】rand/randn/randint/randperm的区别

时间:2023-05-09 16:12:54

相关推荐

【PyTorch】rand/randn/randint/randperm的区别

问题

随机数的应用场景十分广泛,例如搭建完成网络进行测试的时候需要随机输入,PyTorch提供了rand/randn/randint/randperm等多种随机数的生成方法,那么这些方法的区别是什么呢?在实际开发时,应该如何选择呢?

方法

import torch x = torch.zeros(size=(3, 224, 224))# [0, n) 随机序列a = torch.randperm(10)print(a) # tensor([8, 0, 9, 1, 7, 2, 3, 5, 6, 4])# [a,b) 均匀分布, 注意size参数接受的是一个tuple,而不是整数# b = torch.rand(size=1) # rand(): argument 'size' must be tuple of ints, not intb = torch.rand(size=(1, ))b0 = torch.rand_like(x)print(b0.shape)# [a,b) 标准正太分布d = torch.randn(size=(1,))# [a, b) 随机整数c = torch.randint(1, 10, (1,) )

结语

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。