On Mon, Oct 4, 2021 at 1:09 AM <hongyi.z...@gmail.com> wrote: > Thank you for pointing this out. This is the code block which includes the > first appearance of the keyword `logical_not`. > > BTW, why can't the ~ operator be tested equal to 'np.invert', as shown > below: > > ``` > In [1]: import numpy as np > In [3]: np.invert is np.bitwise_not > Out[3]: True > > In [4]: np.invert is ~ > File "<ipython-input-4-32abf1603b17>", line 1 > np.invert is ~ > ^ > SyntaxError: invalid syntax > ``` >
That’s just the way Python’s syntax works. Operators are not names that can be resolved to objects that can be compared with the `is` operator. Instead, when that operator is evaluated in an expression, the Python interpreter will look up a specially-named method on the operand object (in this case `__invert__`). Numpy array objects implement this method using `np.invert`. -- Robert Kern
_______________________________________________ NumPy-Discussion mailing list -- numpy-discussion@python.org To unsubscribe send an email to numpy-discussion-le...@python.org https://mail.python.org/mailman3/lists/numpy-discussion.python.org/ Member address: arch...@mail-archive.com