배열 분리(dsplit)
numpy.dsplit(ary, indices_or_sections)
Python split 함수 참조
차이점은 dsplit은 axis=2에 대해 동등하게 배열을 분리(3D 배열 이상 사용 가능)
▪Parameters
‣ ary : 입력 배열,
‣ indices_or_sections : 정수 입력(Integer), 축을 따라 N개의 배열로 분리
‣ Returns : sub-arrays(list of ndarrays), 분리된 배열 반환
예제(Example)
<Example 01>
import numpy as np
x = np.arange(16.0).reshape(2, 2, 4)
output = np.vsplit(x, 2)
print('x 배열 :\n', x)
print('dsplit 배열 :\n', output)
Result
x 배열 :
[[[ 0. 1. 2. 3.]
[ 4. 5. 6. 7.]]
[[ 8. 9. 10. 11.]
[12. 13. 14. 15.]]]
dsplit 배열 :
[array([[[0., 1., 2., 3.],
[4., 5., 6., 7.]]]), array([[[ 8., 9., 10., 11.],
[12., 13., 14., 15.]]])]
<Example 02>
import numpy as np
arr = np.array([[[1, 2], [3, 4]], [[5, 6], [7, 8]]])
output = np.dsplit(arr, 2)
for idx, array in enumerate(output):
print(f"2D Array {idx + 1}:")
print(array)
print()
Result
2D Array 1:
[[[1]
[3]]
[[5]
[7]]]
2D Array 2:
[[[2]
[4]]
[[6]
[8]]]
<Example 03>
import numpy as np
arr = np.array([[[1, 2, 3], [4, 5, 6]], [[7, 8, 9], [10, 11, 12]]])
output = np.dsplit(arr, [1, 2])
for idx, array in enumerate(output):
print(f"2D Array {idx + 1}:")
print(array)
print()
Result
2D Array 1:
[[[ 1]
[ 4]]
[[ 7]
[10]]]
2D Array 2:
[[[ 2]
[ 5]]
[[ 8]
[11]]]
2D Array 3:
[[[ 3]
[ 6]]
[[ 9]
[12]]]
Numpy 함수 모음
※ 이 글이 도움이 되었다면 "👆🏻구독"과 "🤍공감" 버튼을 클릭해주세요. 클릭 한번이 글 쓰는데 큰 힘이 됩니다.