TIL 191117_2

김상훈·2019년 11월 17일
0

케라스 창시자에게 배우는 딥러닝

텐서란 무엇인가?

# 텐서: 데이터의 컨테이너
# 텐서의 형태: 다차원 배열
# 텐서 형태의 구성요소: 축(rank, axis, demension), 크기(shape), 데이터 타입
# 축은 몇차원 배열인지 알려줌.
# 크기는 각 차원에서 배열의 크기를 알려줌.
# 데이터 타입은 Numpy의 데이터 타입. 보통 float32, unit8, float64 등

# MNIST 데이터의 텐서 형태를 확인해보자.
from keras.datasets import mnist
(train_images, train_labels), (test_images, test_labels) = mnist.load_data()

# 데이터의 축 확인하기 (Numpy에서는 ndim이라는 property? attribute? 사용: n dimension이겟쬬?)
print(train_images.ndim) # 출력: 3

# 데이터의 크기 확인하기 (Numpy)
print(train_images.shape) # 출력 (60000, 28, 28)

# 데이터의 타입 확인하기 (Numpy dtype: data type이겟쬬?)
print(train_images.dtype) # 출력 unit8

# 데이터 직접 확인하기 (Matplotlib 라이브러리 사용)
digit = train_images[4] # 다섯번째 이미지 변수 부여
import matplotlib.pyplot as plt
plt.imshow(digit, cmap=plt.cm.binary) 
# pylint 에러가 있는데, 스킵 가능한듯. 참고: https://github.com/PyCQA/pylint/issues/2289
plt.show()
profile
남과 비교하지 말자.

0개의 댓글