[Python-ideas] Revisiting dedicated overloadable boolean operators
Chris Barker
chris.barker at noaa.gov
Fri Aug 3 17:38:59 EDT 2018
On Fri, Aug 3, 2018 at 1:02 PM, Nicholas Chammas <nicholas.chammas at gmail.com
> wrote:
> The project overloaded the bitwise operators &, |, and ~ since they
> could not
>
override the boolean operators and, or, and not.
>
> I actually think that is a good solution to this problem -- the fact is
that for most data types bitwise operators are useless -- and for even more
not-very-useful.
numpy did not do this, because, as it happens, bitwise operators can be
useful for numpy arrays of integers (though as I write this, bitwise
operations really aren't that common -- maybe requiring a function call for
them would be a good way to go -- too late now).
Also, in a common use-case, bitwise-and behaves the same as logical_and,
e.g.
if (arr > x) & (arr2 == y)
This "works" because both arrays being bitwise-anded are boolean arrays.
So you really don't need to call:
np.logical_and and friends very often.
so -1 on yet another set of operartors.
-CHB
--
Christopher Barker, Ph.D.
Oceanographer
Emergency Response Division
NOAA/NOS/OR&R (206) 526-6959 voice
7600 Sand Point Way NE (206) 526-6329 fax
Seattle, WA 98115 (206) 526-6317 main reception
Chris.Barker at noaa.gov
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20180803/be99c107/attachment-0001.html>
More information about the Python-ideas
mailing list