import numpy as np
A = np.asarray([0, 2, 7, 9, 13])
x = 2
np.split(A, range(x, len(A), x))
# [array([0, 2]), array([7, 9]), array([13])]
Note that as @Divakar mentioned in his comment, you are better off performance wise using loops (or in this case a list comprehension).
def f(seq, n):
return [seq[i:min(i + n, len(seq))] for i in range(0, len(seq), n)]
def g(seq, n):
return np.split(seq, range(n, len(A), n))
%timeit f(range(12345), 109)
65.2µs ± 468ns (mean +- std. dev. of 7 runs, 10000 loops each)
%timeit g(range(12345), 109)
1.32ms ± 5.21 µs (mean +- std. dev. of 7 runs, 10000 loops each)
Edit
Since slicing past the last index will naturally slice till the last element, we can do away with the check
def f(seq, n):
return [seq[i : i + n] for i in range(0, len(seq), n)]