繁体   English   中英

*(Tensors 张量的元组,名称 dim,Tensor out)

[英]* (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_tensorstorch.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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM