AI&BigData/Basics
[Numpy] 자료형, type(), dtype, arange()
eunguru
2018. 4. 24. 20:08
Numpy의 자료형(Data type)
1. 자료형의 종류
1) 정수형(int: integer)
- 부호가 있는 정수형: int8, int16, int32, int64
- 부호가 없는 정수형: uint(unsigned integer): uint8, uint16, uint32, uint64
2) 실수형(float)
- float16, float32, float64
3) 복소수(complex)
- complex64: 두개의 32비트 부동 소수점으로 표시되는 복소수
- complex128: 두개의 64비트 부동소수점으로 표시되는 복소수
4) 부울형(boolean)
- True, False
2. 데이터 타입을 알아보기 위한 type(), dtype 속성
1) type(), dtype
import numpy as np
x = np.float32(1.0)
print(x)
print(type(x))
print(x.dtype)
1.0
<class 'numpy.float32'>
float32
aa = np.array([1,2,3], dtype='f')
print(aa, aa.dtype)
[1. 2. 3.] float32
xx = np.int8(aa)
print(xx, xx.dtype)
[1 2 3] int8
2) arange()
bb = np.arange(10)
print(bb)
[0 1 2 3 4 5 6 7 8 9]
- type지정
bb = np.arange(10, dtype='f')
print(bb, bb.dtype)
[0. 1. 2. 3. 4. 5. 6. 7. 8. 9.] float32
- 시작, 끝 지정
cc = np.arange(3, 10, dtype='f')
print(cc)
[3. 4. 5. 6. 7. 8. 9.]
- 값 생성시 증가값 지정
dd = np.arange(2,3, 0.1)
print(dd)
[2. 2.1 2.2 2.3 2.4 2.5 2.6 2.7 2.8 2.9]