来源:https://www.cnblogs.com/siyuan1998/p/10792481.html

1.1 list 转 numpy

ndarray = np.array(list)

1.2 numpy 转 list

list = ndarray.tolist()

2.1 list 转 torch.Tensor

tensor=torch.Tensor(list)

2.2 torch.Tensor 转 list

先转numpy,后转list

list = tensor.numpy().tolist()

3.1 torch.Tensor 转 numpy

ndarray = tensor.numpy()

*gpu上的tensor不能直接转为numpy

ndarray = tensor.cpu().numpy()

3.2 numpy 转 torch.Tensor

tensor = torch.from_numpy(ndarray)

相关文章:

  • 2021-11-30
  • 2021-06-10
  • 2022-12-23
  • 2021-12-05
  • 2021-08-09
  • 2022-12-23
猜你喜欢
  • 2021-08-07
  • 2021-10-21
  • 2021-07-24
  • 2021-06-15
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案