머신러닝

본문 바로가기
사이트 내 전체검색


머신러닝
머신러닝

2. Numpy 자료형

페이지 정보

작성자 관리자 댓글 0건 조회 1,315회 작성일 20-01-21 20:43

본문

2. Numpy 자료형

int, float, bool(True/ False), complex

 

정수형(int:integer)
 int8(-127~127), int16(-32768 ~ 32767), int32, int64 (부호가 있는 정수형)
uint(Unsigned integer):  uint8(0~255), unit16(0~65535), unit23, unit64


실수형(float)
float16, float32, float64


complex
complex64 : 두개의 32비트 부동소소수점으로 표시되는 복소수
complex128 : 두개의 64비트 부동 소수점으로 표시되는 복소수

데이터의 type을 알아보기위한 dtype속성 

 

실습1.

import numpy as np

x = np.float32(1.0)

print(x)

print(type(x))

print(x.dtype)

[결과]

​1.0
<class 'numpy.float32'>
float32

실습2.

​import numpy as np

x = np.arange(5)
print(x)
print(x.dtype)

z = np.arange(5, dtype='f')
print(z)
print(z.dtype)

aa = np.array([1,2,3], dtype='f')
print(aa)
print(aa.dtype)

[결과]

​[0 1 2 3 4]
int32
[0. 1. 2. 3. 4.]
float32
[1. 2. 3.]
float32

실습3.

​import numpy as np

aa = np.array([1,2,3], dtype='f')
print(aa)
print(aa.dtype)

xx = np.int8(aa)
print(xx)
print(xx.dtype)

[결과]

​[1. 2. 3.]
float32
[1 2 3]
int8

실습4.

​import numpy as np

bb = np.arange(10)
print(bb)

cc = np.arange(3,10, dtype=np.float)
print(cc)

print(cc.dtype)
dd = np.arange(2,3, 0.2)
print(dd)

​[결과]

[0 1 2 3 4 5 6 7 8 9]
[3. 4. 5. 6. 7. 8. 9.]
float64
[2.  2.2 2.4 2.6 2.8]​

댓글목록

등록된 댓글이 없습니다.


개인정보취급방침 서비스이용약관 모바일 버전으로 보기 상단으로

TEL. 063-469-4551 FAX. 063-469-4560 전북 군산시 대학로 558
군산대학교 컴퓨터정보공학과

Copyright © www.leelab.co.kr. All rights reserved.