Python *(张量元组张量,名称dim,张量out)
假设我有一个内存列表Python *(张量元组张量,名称dim,张量out),python,pytorch,Python,Pytorch,假设我有一个内存列表list\u of_tensors=[tensor1,tensor2,tensor3,tensor4]。每个元素都是一个pytorch张量,其形状(1,1,84,84) 我想连接张量列表,得到一个形状为(4,1,84,84)的张量torch.cat(TT,dim=0)可能会允许我这样做TT必须是张量的元组,因此torch.cat(*list\u of theu tensors,dim=0)或torch.cat((*list\u of theu tensors,dim=0)不起
list\u of_tensors=[tensor1,tensor2,tensor3,tensor4]
。每个元素都是一个pytorch张量,其形状(1,1,84,84)
我想连接张量列表,得到一个形状为(4,1,84,84)
的张量torch.cat(TT,dim=0)
可能会允许我这样做TT
必须是张量的元组,因此torch.cat(*list\u of theu tensors,dim=0)
或torch.cat((*list\u of theu tensors,dim=0)
不起作用
如何使用list\u张量
和torch.cat(??,dim=0)
创建形状为(4,1,84,84)的新张量
您可以使用堆栈,并通过挤压移除多余的维度
现在c.形状是(4,1,84,84)
您可以在这里找到解释:请阅读。特别是,请在阅读该页后重写您的标题。当前的一个根本不清楚。在张量列表上使用
torch.cat
也可以。
c = (torch.stack(list_of_tensors,dim=1)).squeeze(0)