传送门: https://blog.csdn.net/liu16659/article/details/114752918
使用 torch.stack(tensor_list,0)
import torchtensor1=torch.tensor([1,2,3])tensor2=torch.tensor([4,5,6])tensor_list=[]tensor_list.append(tensor1)tensor_list.append(tensor2)print(tensor_list)print(type(tensor_list))final_tensor=torch.stack(tensor_list,0)print(final_tensor)print(type(final_tensor))