[Pytorch] numpy, tensor, list 변환
·
언어 | Framework/Pytorch
pytorch에서 자주 쓰이는 형태인 numpy, tensor, list 간에 변환. import torch import numpy as np # numpy to tensor np_arr = np.zeros((3, 3), dtype=np.float32) tensor_arr = torch.from_numpy(np_arr) # tensor to numpy np_arr = tensor_arr.numpy() # tensor to list list = tensor_arr.tolist() # list to tensor tensor_arr = torch.tensor(list) 간단하다.