Add ability to use `batch_size` parameter in `np.array_split`
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 32.8k
- Forks
- 12.8k
- Avg merge
- 1d 7h
- Merged PRs (30d)
- 197
Description
Feature
The np.array_split function takes an indices_or_sections argument which, when it is an integer, makes the function return a list of indices_or_sections subarrays.
For example:
import numpy as np
l = 17 * ['a']
np.array_split(np.array(l), 4)
>>> [array(['a', 'a', 'a', 'a', 'a'], dtype='<U1'),
array(['a', 'a', 'a', 'a'], dtype='<U1'),
array(['a', 'a', 'a', 'a'], dtype='<U1'),
array(['a', 'a', 'a', 'a'], dtype='<U1')]
What I would like it to return it a list of subarrays, all of size batch_size (except maybe the last).
Example of what I want:
import numpy as np
l = 17 * ['a']
np.array_split(np.array(l), batch_size=4)
>>> [array(['a', 'a', 'a', 'a'], dtype='<U1'),
array(['a', 'a', 'a', 'a'], dtype='<U1'),
array(['a', 'a', 'a', 'a'], dtype='<U1'),
array(['a', 'a', 'a', 'a'], dtype='<U1'),
array(['a'], dtype='<U1')]
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the existing np.array_split entry point and its documentation for indices_or_sections. Trace how integer sections are interpreted, then determine how the requested batch_size behavior should fit the existing API and validate the examples in the issue. Done means the behavior is implemented with coverage for full and partial final batches and the documentation reflects the supported usage.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- data
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 32/100