인공지능 (Deep Learning)/딥러닝 및 파이토치 기타 정리
[형변환] Tensor to Numpy / Numpy to Tensor
애플파ol
2023. 12. 23. 13:42
. Numpy → Tensor
output = torch.Tensor(input) # 새로운 메모리에 할당.
output = torch.from_numpy(input) # 기존 메모리에 할당.
(where input is Numpy type, output is Tensor type)
2. Tensor → Numpy
output= np.array(input)
(where input is Tensor type, output is Numpy type)
(암기도 하려고 노력해야 외워진다.)