Numpy + AutoGrad
t_array = torch.FloatTensor(array)
t_array.shape
t_array.ndim
t_array = torch.tensor(list)
t_array.shape
t_array.ndim
slice, flatten, ones_like 등 numpy와 동일하게 적용 됨
x_data.device
다음 함수를 통해 gpu, cpu로 연산할 수 있음
view랑 reshape는 메모리 관련해서 차이가 좀 있는데, view를 쓰면 됨
squeeze, unsqueeze는 (2,2)라면 (1,2,2), (2,1,2), (2,2,1) 요렇게 만들거나 빼거나 해줌
사칙연산은 동일
다만 행렬곱셈은 dot이 아니라 mm 혹은 matmul 을 사용
t1.mm(t2)
t1.matmul(t2)
matmul과 mm의 차이는 matmul은 broadcasting을 지원 (자동으로 차원을 채워줌)
import torch
import torch.nn.functioanl as F
tensor = torch.FloatTensor([0.5,0.7,0.1])
h_tensor = F.softmax(Tensor,dim=0)
h_tensor
# Tensor([0.3458,0.4224,0.2318])
Pytorch의 핵심은 자동 미분의 지원 - Backward 함수 사용