728x90
numpy
9

[Numpy] Reshape

In [2]: import numpy as np In [4]: test_matrix = [[1,2,3,4], [1,2,5,8]] np.array(test_matrix).shape Out[4]: (2, 4) In [5]: np.array(test_matrix).reshape(2, 2, 2) Out[5]: array([[[1, 2], [3, 4]], [[1, 2], [5, 8]]]) In [7]: test = np.array(test_matrix).reshape(8,) test Out[7]: array([1, 2, 3, 4, 1, 2, 5, 8]) -1로 지정해주면 다른 열 또는 행을 기준으로 자동으로 맞춰준다. 예를 들어 다음과 같이 reshape(-1, 1)로 지정해주었다면 1열로 맞추고 행은 따라서 자..

Numpy 2021.07.16

[실습]주성분 분석(Principal Component Analysis, PCA)

1. 데이터 생성 import pandas as pd df = pd.DataFrame(columns=['calory', 'breakfast', 'lunch', 'dinner', 'exercise', 'body_shape']) df.loc[0] = [1200, 1, 0, 0, 2, 'Skinny'] df.loc[1] = [2800, 1, 1, 1, 1, 'Normal'] df.loc[2] = [3500, 2, 2, 1, 0, 'Fat'] df.loc[3] = [1400, 0, 1, 0, 3, 'Skinny'] df.loc[4] = [5000, 2, 2, 2, 0, 'Fat'] df.loc[5] = [1300, 0, 0, 1, 2, 'Skinny'] df.loc[6] = [3000, 1, 0, 1, 1, '..

728x90