-
[Python/Pytorch] 데이터 타입(DataType) 조회하는 방법Debug 2023. 8. 21. 02:56
데이터 타입에 따라 dtype 조회하는 방법이 다르다.
List, Int 등 기본 데이터 타입
# 1 a = dict() type(a) # 2 isinstance(a, dict)
tensor (torch) 데이터 타입
a = torch.zeros(1, 3) torch.is_tensor(a)
tensor.float32 등의 데이터 타입
a = torch.zeros(1, 3) torch.dtype
tensor의 데이터 타입 변환시 아래와 같이 코드를 작성하면 된다. 단, torch.float32는 float 타입이지만, torch.float64는 double 타입으로 인식하는 것에 유의하자.
a = torch.zeros(1, 3, dtype=torch.int32) b = torch.Tensor([1.3, 2.4, 3.5], dtype=torch.float32) # a: int -> float a.type(b.dtype)