import torch
x = torch.rand(2,2)
x1 = x.numpy() # torch转换到numpy
x2 = torch.from_numpy(x1) #numpy转换torch
print("\n torch_x:\n",x,
   "\n numpy_x1:\n",x1,
   "\n torch_x2:\n",x2)

out:

 torch_x:
 tensor([[0.8195, 0.8927],
        [0.7544, 0.8827]]) 
 numpy_x1:
 [[0.8194596 0.8926985]
 [0.754393  0.882745 ]] 
 torch_x2:
 tensor([[0.8195, 0.8927],
        [0.7544, 0.8827]])

 

相关文章:

  • 2022-12-23
  • 2023-03-20
  • 2022-12-23
  • 2022-12-23
  • 2021-11-22
  • 2022-01-15
  • 2022-12-23
猜你喜欢
  • 2021-11-30
  • 2022-12-23
  • 2023-02-10
  • 2023-03-21
  • 2022-12-23
  • 2021-11-24
相关资源
相似解决方案