torch.randn生成随机整数
时间: 2023-10-15 12:25:34 浏览: 151
torch.randn函数生成的是服从标准正态分布(0~1)的随机数,而不是随机整数。如果你需要生成随机整数,可以使用torch.randint函数。torch.randint(low, high, size)可以生成一个给定范围内的随机整数张量,其中low是下界,high是上界,size是张量的形状。例如,如果你想生成一个形状为(3, 4)的随机整数张量,范围在0到10之间,可以使用torch.randint(0, 10, (3, 4))。<span class="em">1</span><span class="em">2</span><span class="em">3</span>
#### 引用[.reference_title]
- *1* [torch.randn()用法](https://blog.csdn.net/ranrankeai/article/details/127849613)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"]
- *2* *3* [Pytorch常用的4种随机数生成方法](https://blog.csdn.net/weixin_37926734/article/details/126614099)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"]
[ .reference_list ]
阅读全文