Programming
numpy reshape 함수 사용하기
engyjoon
2021. 1. 20. 11:31
배열에 포함된 요소가 사라지지 않는 형태라면 자유롭게 reshape할 수 있다.
reshape 함수 파라미터에 -1을 입력하면 나머지 axis 수를 계산해준다.
import numpy as np
list_a = [1, 2, 3, 4, 5, 6]
narr_a = np.array(list_a)
narr_b = narr_a.reshape(2, 3)
print(narr_b)
print()
narr_c = narr_b.reshape(3, -1)
print(narr_c)
[[1 2 3]
[4 5 6]]
[[1 2]
[3 4]
[5 6]]