[英]* (tuple of Tensors tensors, name dim, Tensor out)
假設我有 memory 列表list_of_tensors = [tensor1, tensor2, tensor3, tensor4]
。 每個元素都是一個形狀為(1, 1, 84, 84)
的 pytorch 張量。
我想連接該張量列表以獲得形狀(4, 1, 84, 84)
的張量。 torch.cat(TT, dim=0)
肯定可以讓我這樣做。 TT
必須是張量的元組,因此torch.cat(*list_of_tensors, dim=0)
或torch.cat((*list_of_tensors), dim=0)
將不起作用。
如何使用list_of_tensors
和torch.cat(???, dim=0)
創建形狀為(4, 1, 84, 84)
的新張量
您可以使用stack ,並使用擠壓去除多余的尺寸
c = (torch.stack(list_of_tensors,dim=1)).squeeze(0)
現在 c.shape 是 (4, 1, 84, 84)
你可以在這里找到解釋: https://discuss.pytorch.org/t/how-to-turn-a-list-of-tensor-to-tensor/8868/6
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.