본문 바로가기

MLOps 개발자 양성과정/ml&dl

[Day-59] 생활코딩2부

chap12

 

 

가로를 행, 레코드, 샘플, 관측치, row 이라고 불려

세로를 열 변수, column

데이터프레임은 시리즈(데이터 타입 달라로o)가 기본요소/ 리스트

 

 

<데이터프레임 이해하기>

 

넘파이 차원 확인하기
- shape : 구조 구성을 확인
- ndim : 차원만 확인하는 함수
import numpy as np
import matplotlib.pyplot as plt​
x1 = np.array([1, 2, 3, 4]) #반드시 리스트 형태로 들어가
print(x1.ndim, x1.shape)
# dim 차원, # 구성을 봐

>>> 1 (4,)
# 4 숫자가 어디로 가는 지 확인

# X2, X3 생성
x2 = np.array([5,6,7,8])
x3 = np.array([9,10,11,12])

# 리스트로 묶기
아이리스 = np.array([x1, x2, x3])
# 1차원 짜리를 묶었어 => 나열돼(뒤로 쌓이는게 아님. rehaspe 해야 해)
print(아이리스.ndim, 아이리스.shape)

>>> 2 (3, 4) 
# 2차원  (3행 4열)
# 차원 곧 배열의 깊이

 

dl = np.array([1, 2, 3])
print(dl.ndim, dl.shape)
>>> 1 (3,)


d2 = np.array([dl, dl, dl, dl, dl]) 
print(d2.ndim, d2.shape)
>>> 2 (5, 3)

d3 = np.array([d2, d2, d2, d2]) # 2차원을 나열 더 못해 쌓여 3차원으로
print(d3.ndim, d3.shape)
>>> 3 (4, 5, 3)​

 

이미지 차원

# 이미지
img1 = np.array([[0, 255], [255, 0]]) # 0: 검정 / 255: 하양
print(img1.ndim, img1.shape)

plt.imshow(img1,cmap='gray',) #colormap=cmap
plt.show()​

img2 = np.array([[255, 255], [255, 255]])
img3 = np.array([[0, 0], [0, 0]])
# 이미지는 하나의 픽셀이 하나의 차원이야
# 3d차원과 달라