* (张量张量的元组,名称 dim,张量输出)

假设我有内存列表。每个元素都是形状的pytorch张量。list_of_tensors = [tensor1, tensor2, tensor3, tensor4](1, 1, 84, 84)

我想连接张量列表以获得形状的张量。 也许肯定会允许我这样做。 必须是张量的元组,所以或不起作用。(4, 1, 84, 84)torch.cat(TT, dim=0)TTtorch.cat(*list_of_tensors, dim=0)torch.cat((*list_of_tensors), dim=0)

如何使用和创建新的形状张量list_of_tensorstorch.cat(???, dim=0)(4, 1, 84, 84)


慕的地6264312
浏览 121回答 1
1回答

慕桂英546537

您可以使用堆栈,并通过挤压去除多余的尺寸c = (torch.stack(list_of_tensors,dim=1)).squeeze(0)现在 c.形状是 (4, 1, 84, 84)你可以在这里找到解释:https://discuss.pytorch.org/t/how-to-turn-a-list-of-tensor-to-tensor/8868/6
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Python