Syntax:
np.split(ary, indices_or_sections, axis=0)
ary: The array to be split.
indices_or_sections: Number of equal sections or list of indices.
axis: Axis along which to split (default is 0).
import numpy as np
arr = np.array([1, 2, 3, 4, 5, 6])
split_arr = np.split(arr, 3)
print(split_arr)
[array([1, 2]), array([3, 4]), array([5, 6])]
import numpy as np
matrix = np.array([[1, 2, 3, 4],
[5, 6, 7, 8]])
split_matrix = np.split(matrix, 2, axis=1)
print(split_matrix)
[array([[1, 2],
[5, 6]]),
array([[3, 4],
[7, 8]])]