-
-
Notifications
You must be signed in to change notification settings - Fork 10.9k
-array(True) == False #4100
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
Well, numpy bools are not really python bools (since python bools are basically ints, numpy's are not). The whole definition of
|
Note that it was different in Numeric:
I was not able to find any place where this behavior is documented and it is very surprising when boolean arrays are not interchangeable with integer 0/1 arrays in expressions. For example:
|
Yeah, it sure would make more sense for negation on bools to be either a Not sure if we can actually fix it at this point. Maybe we should make unary - on bools just raise an error for now? That'd
|
We don't:
in Z/2 ring this would be False or 0. As implemented, numpy bools form an idempotent semiring with respect to + and * operations. In a semiring addition does not have an inverse, so this observation does not help to define unary minus. I think + and - should either promote bools to ints or raise an error. Given that semiring operations are already available as | and & operators and current unary minus is the same as ~, it is hard to see the utility of current implementation. |
Good point, I skimmed @seberg's message too quickly :-). Right now we have + is the same as |, * is the same as &, binary - is the I agree that the ideal behaviour is for these to either error or promote to I'd be +1 on a patch deprecating +/-/* for numpy bools. On Wed, Dec 4, 2013 at 9:00 PM, abalkin notifications@github.com wrote:
Nathaniel J. Smith |
Gave the deprecation a shot in gh-4105. In principle I tihnk it is good, but the impact on real live code might be rather large. I did not yet do any of the fixes in numpy itself (maybe you want to have a look at it and send a PR against me PR -- yes that is possible -- or a patch). The thing I am unsure about is, after this has been deprecated a while, what integer type do you cast it to? int8? |
My first guess would be to upcast to dtype(int), but no point in worrying
|
I agree with changing the behaviour to something nicer, but it should be discussed on the list first. That said, I doubt there will be much disagreement or that many rely on current behavior. |
Unary |
NumPy behavior is inconsistent with that of python builtins:
but
The text was updated successfully, but these errors were encountered: