question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

BUG: np.reshape sometimes returns scalars

See original GitHub issue
In [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:open
  • Created 7 years ago
  • Reactions:1
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
eric-wiesercommented, Jun 17, 2020

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

reshape doesn’t make any promise of returning a view, so I think we’re off the hook for returning a writeable array copy.

0reactions
sebergcommented, Jun 17, 2020

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found