使用Pytorch的过程中,经常涉及到变量需要在list,numpy和tensor之间自由转化。
1.1 list 转 numpy
ndarray = np.array(list)
1.2 numpy 转 list
list = ndarray.tolist()
2.1 list 转 torch.Tensor
tensor=torch.Tensor(list)
使用Pytorch的过程中,经常涉及到变量需要在list,numpy和tensor之间自由转化。
1.1 list 转 numpy
ndarray = np.array(list)
1.2 numpy 转 list
list = ndarray.tolist()
2.1 list 转 torch.Tensor
tensor=torch.Tensor(list)