I know that np.array_split allows us to split a NumPy array, but the number of elements in the split arrays only depends on the number of split chunks. The following example shows what I get and what I wish to get (the size of my_array is 35):
my_array = [1 1 1 1 1 0 0 0 1 1 0 1 1 1 0 1 0 1 0 0 0 0 1 0 0 1 0 1 1 0 0 1 1 1 1]
np.array_split(my_array, 5) outputs:
[array([1, 1, 1, 1, 1, 0, 0]),
array([0, 1, 1, 0, 1, 1, 1]),
array([0, 1, 0, 1, 0, 0, 0]),
array([0, 1, 0, 0, 1, 0, 1]),
array([1, 0, 0, 1, 1, 1, 1])]
AND
np.array_split(my_array, 4) outputs:
[array([1, 1, 1, 1, 1, 0, 0, 0, 1]),
array([1, 0, 1, 1, 1, 0, 1, 0, 1]),
array([0, 0, 0, 0, 1, 0, 0, 1, 0]),
array([1, 1, 0, 0, 1, 1, 1, 1])]
However, what I need is split arrays with 8 elements like this:
[array([1, 1, 1, 1, 1, 0, 0, 0]),
array([1, 1, 0, 1, 1, 1, 0, 1]),
array([0, 1, 0, 0, 0, 0, 1, 0]),
array([0, 1, 0, 1, 1, 0, 0, 1]),
array([1, 1, 1])
I know that np.array_split(my_array, [8, 16, 24, 32]) can give me the answer for this specific question, but what I wish to do is that, for any size of an array, I could split it into arrays with a specific number of elements except for the last one if the array is not divisible.