Array 의 초기화 함수들(zeros,ones,full,eye)
np.zeros
ar = np.zeros((3,4))
printinfo(ar)
np.zeros()는 배열의 모든 원소에 0을 삽입한다.
np.ones
array = np.ones((2,3))
print(array)
np.ones()는 배열의 모든 원소에 1을 삽입한다.
np.full
array= np.full((2,3), 1234)
print(array)
np.full()은 배열에 사용자가 지정한 값을 삽입합니다.
np.eye
array = np.eye(3)
print(array)
주 대각선의 원소가 모두 1이며 나머지 원소는 모두 0인 정사각형 행렬을 반환. (단위행렬)
참고
np.ranodm.random
array = np.random.random((3,4))
printinfo(array)
np.random.random()은 임의의 값을 가지는 배열을 생성
np.arange()
np.arange(x)는 0부터 x-1까지의 값을 가지는 배열을 생성한다.
# 1부터 9까지 +2씩 적용되는 범위
n = 2
range_n_step_vec = np.arange(1, 10, n)
print(range_n_step_vec)
1부터 9까지 2씩 늘어나는 값을 가진 배열 생성
np.reshape()
np.reshape()은 내부 데이터는 변경하지 않으면서 배열의 구조를 바꾼다.
np.reshape(변경할 배열, 차원) 또는 배열.reshape(차원)
ar.shape
ar1 = np.reshape(ar,(6,4))
print(ar1)
기존 ar 배열은 1차원의 24개의 요소를 가진 데이터였다.
배열을 reshape 하면서 2차원 구조로 다음과 같이 바꿀 수 있다.
3차원으로도 손 쉽게 바꿀 수 있다.
'Pandas' 카테고리의 다른 글
[Pandas] Numpy 배열 인덱싱/슬라이싱 (0) | 2022.11.02 |
---|---|
[Pandas] Numpy - matplotlib, seaborn를 이용한 자료 시각화 (2) | 2022.11.01 |
[Pandas] Numpy (0) | 2022.11.01 |
[Pandas] Google Colab Notebooks 이용해보기 (with Google Drive) (0) | 2022.10.31 |
[Pandas] Data 다루기 (About : null data) (2) | 2022.10.30 |
댓글