0

How do i split a numpy array by input(), however if there is not enough values to evenly split, just split with the remaining values

Example for clarity:

Arr = np.array([1, 2, 4, 7, 9])

if the user inputs 3 split the array by 3 but if there are not enough values to evenly split, just put the remaining values in one split

#Output
[[1, 2, 4], [7, 9]]

1 Answer 1

0

Maybe are you looking for something like this?

N = 3
np.array_split(Arr, range(N, len(Arr), N))

From here: How to split a numpy array into arrays with specific number of elements

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.