Records of/Learning
[Numpy] 06. Array Aggregation functions
data_soin
2021. 7. 25. 16:48
- Aggregation functions
: 전체 데이터 값에 대해 수치적 계산을 해 주는 함수
mat1
array([[-0.92644426, 0.45063478, 0.61315517],
[-0.32615381, 1.10159801, -0.91424833],
[-0.69560478, 0.01941608, 0.18662921],
[ 1.30146264, -1.1894387 , -0.11196524],
[ 0.23942379, -0.21262613, -0.11753845]])
# 15개 숫자의 총합.
np.sum(mat1)
axis : 기본 축을 의미
axis=0 column 을 기준으로 연산
axis=1 은 row 를 기준으로 연산
# 다른 축으로 더해보기
np.sum(mat1, axis=0)
np.sum(mat1, axis=1)
# 평균
np.mean(mat1)
# 중간값
np.median(mat1)
random.randn이 아닌 random.rand는 0과 1사이의 수만 범위로 갖기 떄문에 음수를 포함하지 않는다.
mat3 = np.random.rand(5, 3)
mat3
np.mean(mat3)
np.mean(mat3, axis=0)
np.mean(mat3, axis=1)
np.std(mat3) # 표준편차
# column 별 최소값들
np.min(mat3, axis=0)
# row 별 최댓값
np.max(mat3, axis=1)
# 최소값이 있는 column 별 Index
np.argmin(mat3, axis=0)
# 최대값이 있는 row 별 Index
np.argmax(mat3, axis=1)
# 누적 합
np.cumsum(mat3).reshape(5, 3)
np.cumsum(mat3, axis=1) # row별 누적합.
np.cumprod(mat3, axis=0) # column별 누적 곱.
# 그냥 정렬 --default는 row 별 정렬
np.sort(mat3)
# column 별 정렬
np.sort(mat3, axis=0)
# index를 정렬
# argument sorting에서 정렬된 값의 원래 위치
# 정렬된 다음의 index를 원래 원소의 위치에 표시
np.argsort(mat3)
# np.argsort(mat3, axis=0)