torch.repeat()

PyTorch中的repeat()函数可以对张量进行重复扩充。

>>> a= torch.arange(24).reshape(1,2,3,4)
>>> print(a.size())
torch.Size([1, 2, 3, 4])
>>> print("b.size",a.repeat(2,2,2,2).size())
b.size torch.Size([2, 4, 6, 8])
>>> print("b.size",a.repeat(2,2).size)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
RuntimeError: Number of dimensions of repeat dims can not be smaller than number of dimensions of tensor
posted @ 2022-09-05 17:19  魏晋南北朝  阅读(370)  评论(0编辑  收藏  举报