-
-
Notifications
You must be signed in to change notification settings - Fork 10.9k
DOC: np.append docs should explain how appending different dtypes works #26291
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
It's intended behavior, but it should be documented better. |
@rkern Can I work on a PR to document this behaviour? In that case can you assign this issue to me? |
What is "intended" in changing dtype of array, which values are not changed¿ |
Both arguments are converted to >>> np.asarray([]).dtype
dtype('float64') If you want to work around this, even in the case of empty lists, be sure to coerce both of your arguments to >>> a = np.array([1, 2], dtype=int)
>>> b = np.array([], dtype=int)
>>> np.append(a, b)
array([1, 2]) |
For what it's worth, I would agree that for There was discussion (maybe even a PR?) to add a (For the empty list case, the Improving the docs is also good of course. |
Describe the issue:
When trying to append empty list to existing array, numpy array changes its dtype. This is absolutely not obvious behaviour and I've barely found this problem.
It may sound like minor problem, but in my case it was a reason of not deleting about 50k images by its indices, when I had to.
Reproduce the code example:
Error message:
No response
Python and NumPy Versions:
Python 3.11.5
Numpy 1.26.4
Runtime Environment:
No response
Context for the issue:
No response
The text was updated successfully, but these errors were encountered: