I’m new to NumPy and still figuring out what’s easy to do with built-ins, vs. rolling my own.
I’m trying to split an array, but have the unevenness in subarrays be distributed evenly throughout the result.
To illustrate, if I run the following in numpy:
a = np.arange(17)
for c in [3, 5, 10]:
chunks = np.array_split(a, c)
sizes = np.array([x.size for x in chunks])
print(f'{c} chunks sizes: {sizes}')
The output I get is:
3 chunks sizes: [6 6 5]
5 chunks sizes: [4 4 3 3 3]
10 chunks sizes: [2 2 2 2 2 2 2 1 1 1]
I’d like it to set the sizes gradually to adjust for unevenness, rather than greedily. In other words, I’d like the output to look more like:
3 chunks sizes: [6 5 6]
5 chunks sizes: [3 4 3 4 3]
10 chunks sizes: [2 2 1 2 2 1 2 2 1 2]
Is there a clean way to do this with NumPy builtins, or is the only good way to roll my own (rounding up/down as needed)? From what I’ve found in the docs so far, I most likely have to roll my own.