ndarray의 head, tail 구하기

nØthing specia¡|2019년 12월 20일
Posts

ndarray의 head, tail 구하기

nØthing specia¡|2019년 12월 20일

데이터프레임을 사용하는 경우 데이터의 앞뒤를 head와 tail을 사용하여 구하는 데, ndarray타입인 경우 head, tail이 따로 없다. 이런 경우 슬라이싱 연산자를 사용한다. import numpy as np # 데이터 머리부터 두 개의 데이터를 가져온다 head = np.array((1,2,3,4,5))[:2] # 중간 3,4번째 데이터를 가져온다 body = np.array((1,2,3,4,5))[2:4] # 꼬리에서 두 개의 데이터를 가져온다 tail = np.array((1,2,3,4,5))[-2:] print(head) print(body) print(tail) # 슬라이싱 말고 아래와 같이 제한적이긴 하지만 일부 데이터를 가져 오는 데 # 아래의 *