假设我有内存列表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)
形张量
您可以使用堆栈,并使用挤压删除多余的维度
现在c.形状是(4,1,84,84)
你可以在这里找到解释:https://discuss.pytorch.org/t/how-to-turn-a-list-of-tensor-to-tensor/8868/6
相关问题 更多 >
编程相关推荐