pytorch tensor 다루기 재활치료 2편 - view, squeeze, unsqueeze, type, cat, stack, ones_like, zeros_like, inplace -

1. view 원소의 수를 유지하면서 tensor의 크기를 변경하는 방법 numpy의 reshape와 같은 역할 t = np.array([[[0,1,2], [3,4,5]], [[6,7,8], [9,10,11]]]) ft = torch.FloatTensor(t) print(ft.shape) torch.Size([2, 2, 3]) 1-1) 이제 ft tensor를 view를 사용해서 2차원 tensor로 변경 print(ft.view([-1,3])) #ft라는 텐서를 (?,3)의 크기로 변경 print(ft.view([-1,3]).shape) tensor([[ 0., 1., 2.], [ 3., 4., 5.], [ 6., 7., 8.], [ 9., 10., 11.]]) torch.Size([4, 3]) vie..