난수 생성
np.random.rand(shape)
shape 형태의 배열을 생성하고 [0,1)
의 uniform distribution 형태로 난수를 생성하여 초기화
실행결과

np.random.randn(shape)
shape 형태의 배열을 생성하고 표준 정규분포로부터 난수를 생성하여 요소를 초기화
실행결과

Reshape
- numpy는 shape을 변경할 수 있음
- reshape 시 element 개수는 동일해야 함
reshape(n,m)
실행결과

reshape(n,-1)
- -1은 해당 axis를 numpy가 자동으로 판단하게 함
실행결과

- reshape(-1,1)은 데이터 형태를 맞추기 위해 사용됨
실행결과
- reshape(1,-1)은 flatten()과 동일
실행결과
Indexing & Slicing
- numpy 배열의 요소는 index 배열로 참조할 수 있으며 참조 후 값의 수정이 가능함
- N차원 배열은 N개의 index를 참조할 수 있음
Indexing
실행예시

Slicing
:
를 활용하여 여러개의 배열을 참조하는 슬라이싱을 사용함
- axis별 범위를 지정하여 (시작 인덱스):(끝 인덱스) 형태를 가짐
- (시작 인덱스),(끝 인덱스) 생략 시 처음부터 끝까지를 의미함
- 각 인덱스는 음수로 지정이 가능하며 -1은 맨 마지막 요소
실행예시

Fancy Indexing
- Indexing & Slicing에서는 view를 생성함
- Fancy Indexing에서는 copy를 생성함
실행예시
Slicing과 shape의 유의점
- dot과 같은 연산 시 shape을 확인해줘야함
실행예시

Boolean numpy indexing and masking
- Mask 배열은 boolean 값으로 이루어진 배열로 동일한 shape을 가지는 다른 배열의 index로 활용할 수 있음
- Mask indexing을 수행한 결과는 mask 배열의 True인 요소만이 추출되어 1차원 배열로 나타남
실행예시

열 indexing
- 작업할 열을 지정할 수 있으며 선택한 열에 대해 조건을 지정할 수 있음
실행예시

numpy 연산
기본 연산
실행예시

배열 비교
실행예시
행렬 곱
실행예시
Aggregate function
- numpy는 배열의 합, 평균, 최대/최소값 등의 함수를 제공함
- 이 함수들은 axis를 기준으로 계산됨
실행예시

- 배열의 평균, min, max도 유사하게 동작함
실행 예시
Index 찾기 = arg function
실행예시

np.where()
실행예시

slicing with where
실행예시
numpy broadcasting
- numpy는 shape이 다른 두 배열에 대한 연산을 지원함
- 두 배열의 shape을 임의로 조절하여 연산을 수행
실행예시
np.unique
실행예시
np.concatenate((a1,a2,...),axis=0,out=None)
- a1, a2를 axis 기준으로 병합
- 병합되는 array들은 기준이 되는 axis를 제외하고는 모두 동일한 dimension을 가짐