11-pytorch中 list 转换为 tensor 张量方法 torch.stack(tensor_list,0)

传送门: 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))
THE END
分享
二维码
< <上一篇
下一篇>>