-
-
Notifications
You must be signed in to change notification settings - Fork 10.9k
deprecate isscalar, change behavior? #19690
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
#11882 was the first step towards a possible deprecation, which documented the reasons to avoid |
Talking about the above situation depreciating |
I agree! I wouldn't vote for their deprecation though because there are many situations where you want scalars to be treated just like arrays, e.g., when evaluating functions ("vectorization"). |
I don't think changing the behavior of I'd argue that 0D arrays have their place, and I don't think for a moment would be a good idea to remove |
It is a common argument to get rid of scalars, but What is a "scalar" in NumPy depends, there are at least three definitions:
(I guess 2. and 3. could also be solved with a three-way function that returns And note that the We should not change |
Right now,
np.isscalar
returnsTrue
iff the input is a Python scalar:However,
np.array
s withndim == 0
smell, taste, and behave like Python scalars in almost all situations, so you almost always want to admit ndim-0 arrays when writingif np.isscalar(a): ...
. Unfortunately, downstream usesisscalar
far more often (e.g. scipy: 61isscalar
, 9ndim
). This begs the question ifnp.isscalar
should be deprecated or its behavior changed toThe text was updated successfully, but these errors were encountered: