Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/318.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/flutter/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python *(张量元组张量,名称dim,张量out)_Python_Pytorch - Fatal编程技术网

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)