1. 3차원 데이터 수직으로 붙여 2차원 데이터로 표현하기
- 우리가 다룰 데이터는 mlist이고, 데이터의 shape은 다음과 같다.
(train_images, train_labels), (test_images,test_labels)= tf.keras.datasets.mnist.load_data()
train_images.shape
- 행 28 열 28인 데이터 총 60000개의 면으로 구성되어 있다.
- 면 하나를 하나의 행으로 만들도록 하려면 코드를 다음과 같이 구성하면 된다.
m,n,r = train_images.shape
out_arr = np.column_stack((np.repeat(np.arange(m),n),train_images.reshape(m*n,-1)))
out_df = pd.DataFrame(out_arr)
2. 3차원 데이터를 수직으로 붙여 하나의 열, 다수의 행으로 표현
- 28 x 28 의 데이터를 하나의 행으로 표현하고 싶을 때는 다음과 같이 코드를 구성하면 된다.
pd.DataFrame(dict(rows = list(train_images)))