I have a arrays stored in a list and want to split the list sublists. This is my list:
all_data=[np.array([[1., 2.]]), np.array([[7., 7.], [4., 1.]]),\
np.array([[-1., 4.], [1., 9.]]), np.array([[3., 0.]]),\
np.array([[0., -2.]]), np.array([[6., 1.], [3., 5.]])]
It has 6 arrays an I want to split it ito two sublist. First sublist includes first three arays and second one inclused the last three arrays. It will be:
spl_data=[[np.array([[1., 2.]]), np.array([[7., 7.], [4., 1.]]),\
np.array([[-1., 4.], [1., 9.]])],\
[np.array([[3., 0.]]),\
np.array([[0., -2.]]), np.array([[6., 1.], [3., 5.]])]]
I tried the fillowing function:
def chunks(lst, n):
for i in range(0, len(lst), n):
yield lst[i:i + n]
Then I tried the following to get what I want but it was not successful:
n=2
spl_data=list(chunks(all_data, n))
I do appreciate any help in advance.