apply_along_axis cuts strings
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 32.8k
- Forks
- 12.8k
- Avg merge
- 1d 7h
- Merged PRs (30d)
- 197
Description
I'm trying to concatenate all elements of a row into a string as follows:
np.apply_along_axis(lambda x: " ".join(map(str, x)), 1, b)
b is
[[111,111,0,0,0], [111,111,111,111,111]]
However, the result of the line is:
['111 111 0 0 0', '111 111 111 1']
It looks like np.apply_along_axis is cutting the second string to be of the same length as the first one. If I put a longer sequence first, the result is correct:
['111 111 111 111 111', '111 111 0 0 0']
So I'm guessing this is a bug?
Summary 2019-04-30 by @seberg
np.apply_along_axis infers the output dtype from the first pass. Which can be worked around for example but the function returning an array of a correct type.
Actions:
np.apply_along_axiscould/should get adtypekwarg (or similar, compare alsonp.vectorize).
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 at the np.apply_along_axis entry point and reproduce the supplied example, comparing results when the longer row comes first or second. Determine how the first pass sets the output dtype; done means the example preserves both complete strings, with the chosen dtype-handling behavior reflected in the API.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- data
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100