BUG: np.reshape sometimes returns scalars
See original GitHub issueIn [2]: np.reshape(int(0), ())
Out[2]: array(0)
In [3]: np.reshape(np.int64(0), ())
Out[3]: 0
I would prefer the first behavior for both. In fact, I don’t know how to get an array(0) from an np.int64(0) right now.
np.__version__
is "1.11.0"
Issue Analytics
- State:
- Created 7 years ago
- Reactions:1
- Comments:5 (4 by maintainers)
Top Results From Across the Web
Scalars raise typing errors for ndenumerate, reshape ... - GitHub
Basically, numpy will cast scalars to zero-dimensional arrays, while numba will throw a typing error for a few of its functions.
Read more >Error (only size-1 arrays can be converted to Python scalars ...
According to the docs the result of argrelextrema is a tuple, one array per dimension of the input. In fact the code shows...
Read more >Only size-1 arrays can be converted to Python scalars
This tutorial explains how to fix the following error in Python: only size-1 arrays can be converted to python scalars.
Read more >Scalars — NumPy v1.24 Manual
They can be detected using the hierarchy: For example, isinstance(val, np.generic) will return True if val is an array scalar object.
Read more >Units — Brian 2 2.5.1 documentation
In Brian 1, a distinction is made between scalars and numpy arrays ... 1 + 1 * mV raised an error) whereas arrays...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
reshape
doesn’t make any promise of returning a view, so I think we’re off the hook for returning a writeable array copy.Sounds like the scalars
.reshape()
method is just a bit wrong? The problem I see here, is that I do think reshape should return an array always, however, the scalar is write-only, so that is a bit strange.Not sure if gh-14489 is too directly involved, but I don’t have an immediate idea of how to best fix/think about this.