본문 바로가기
인공지능/데이터 분석

[numpy] array, reshape concatenate, split

by julysein 2020. 10. 4.
728x90
import numpy as np

numpy 를 np 로 불러온다. 

 

array

test = np.array([1,2,3],[4,5,6])

[1,2,3]

[4,5,6]

형태의 행렬 만들어짐

 

reshape

test1 = test.reshape(3,2)

[1,2]

[3,4]

[5,6]

과 같이 바뀜 행렬의 모양을 바꿔주는 함수

 

concatenate

test1 = np.array([[1, 2], [3, 4]])
test2 = np.array([[5, 6], [7, 8]])
result1 = numpy.concatenate((A, B), axis = 0)
result2 = numpy.concatenate((A, B), axis = 1)

concatenate는 두 개의 array를 합치는 함수이다.

axis=0 인 경우 세로로 합쳐지고 axis=1 인 경우 가로로 합쳐진다. 

 

result1 :

[1,2]

[3,4]

[5,6]

[7,8]

 

result2:

[1,2,5,6]

[3,4,7,8]

728x90