ndarray = np.array(list) # list 转 numpy数组
list = ndarray.tolist() # numpy 转 list
tensor=torch.Tensor(list) # list 转 torch.Tensor
list = tensor.numpy().tolist() # torch.Tensor 转 list 先转numpy,后转list
ndarray = tensor.cpu().numpy() # torch.Tensor 转 numpy *gpu上的tensor不能直接转为numpy
tensor = torch.from_numpy(ndarray) # numpy 转 torch.Tensor
- 1
- 2
- 3
- 4
- 5
- 6
文章知识点与官方知识档案匹配,可进一步学习相关知识
Python入门技能树首页概览416686 人正在系统学习中
评论记录:
回复评论: