본문 바로가기

공부(Deep learning)/구현-기초

[tensorflow] mnist 데이터 reshape 하기

Numpy - reshape



*numpy의 reshape 함수는 numpy 데이터의 shape를 변경하고 싶을때 유용한 함수입니다.


*reshape는 원래 데이터를 변경하지않고 반환된 결과를 사용하는 방식으로 사용됩니다.


*reshape의 인자 -1은 일단 해당 자리 부분의shape는 비워두고 다른 차원의 shape가 다 결정됬을경우 남은 부분만큼 알아서 shape를 결정하는것을 의미합니다.






Implementation




코드:

import tensorflow as tf
from tensorflow.examples.tutorials.mnist import input_data
mnist = input_data.read_data_sets("./mnist/data/", one_hot=True)


#print(mnist)
train = mnist.train
temp = train.images.reshape(-1,28,28)

print(temp.shape)


결과:

Extracting ./mnist/data/train-images-idx3-ubyte.gz
Extracting ./mnist/data/train-labels-idx1-ubyte.gz
Extracting ./mnist/data/t10k-images-idx3-ubyte.gz
Extracting ./mnist/data/t10k-labels-idx1-ubyte.gz
(55000, 28, 28)