torch.repeat()
时间: 2023-10-31 19:55:10 浏览: 65
torch练习.py
torch.repeat()函数是一个用于对张量进行重复扩充的函数。这个函数有两种使用方式:
1) 当只有两个参数时,表示行的重复倍数和列的重复倍数,其中1表示不重复。
2) 当有三个参数时,表示通道数的重复倍数,行的重复倍数和列的重复倍数,其中1表示不重复。同样,我们也可以使用x.repeat(4,1)来在行上对x进行重复4次,得到一个二维张量x2 = tensor([[1, 2, 3],
[1, 2, 3],
[1, 2, 3],
[1, 2, 3]])。如果我们有一个二维张量y = torch.tensor([[1, 2],
[3, 4]]),我们可以使用y.repeat(2,3,1)来对y进行重复扩充,得到一个三维张量y3 = tensor([[[1, 2],
[3, 4],
[1, 2],
[3, 4],
[1, 2],
[3, 4]],
[[1, 2],
[3, 4],
[1, 2],
[3, 4],
[1, 2],
[3, 4]]])。<span class="em">1</span><span class="em">2</span><span class="em">3</span>
#### 引用[.reference_title]
- *1* [torch中repeat()函数的准确理解](https://blog.csdn.net/weixin_41041772/article/details/123296659)[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^v92^chatsearchT0_1"}}] [.reference_item style="max-width: 50%"]
- *2* *3* [Pytorch中torch.repeat()函数解析](https://blog.csdn.net/flyingluohaipeng/article/details/125039368)[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^v92^chatsearchT0_1"}}] [.reference_item style="max-width: 50%"]
[ .reference_list ]
阅读全文