PyTorch에서 데이터 타입이라고 하면, 기본 구조인 tensor가 저장하는 값의 dtype을 의미한다. (ex) int, float)
a = torch.tensor(1, dtype = torch.uint8)a = torch.tensor(-1, dtype = torch.int8)a = torch.tensor(1, dtype = torch.short) 혹은a = torch.tensor(1, dtype = torch.int16) 로도 표현할 수 있다.a = torch.tensor(1, dtype = torch.int) 혹은a = torch.tensor(1, dtype = torch.int32) 로도 표현할 수 있다.a = torch.tensor([[1, 2, 3], [4, 5, 6]], dtype = torch.long) 혹은a = torch.tensor([[1, 2, 3], [4, 5, 6]], dtype = torch.int64) 로도 표현할 수 있다.◎ 실수형 데이터 타입은 신경망의 수치 계산에서 사용된다.
◎ 아래에서 나오는 부동 소수점, 가수부, 지수부에 대한 자세한 설명은 여기 참조.
a = torch.tensor(1, dtype = torch.float32) 혹은a = torch.tensor(1, dtype = torch.float) 로도 표현할 수 있다.a = torch.tensor([[1, 2, 3], [4, 5, 6]], dtype = torch.double) 혹은a = torch.tensor([[1, 2, 3], [4, 5, 6]], dtype = torch.float64) 로도 표현할 수 있다.타입 캐스팅이란 어떤 데이터 타입을 다른 데이터 타입으로 변환하는 것을 의미한다.
a = torch.tensor([1, 2, 33], dtype = torch.int8)
b = a.float()
c = a.double()