Understanding the working mechanis of python unary arithmetic operators.
hongy...@gmail.com
hongyi.zhao at gmail.com
Sun Oct 3 20:24:44 EDT 2021
On Sunday, October 3, 2021 at 9:55:15 PM UTC+8, hongy... at gmail.com wrote:
> On Sunday, October 3, 2021 at 8:38:16 PM UTC+8, ju... at diegidio.name wrote:
> > On Sunday, 3 October 2021 at 14:21:13 UTC+2, hongy... at gmail.com wrote:
> > > On Sunday, October 3, 2021 at 6:31:05 PM UTC+8, ju... at diegidio.name wrote:
> >
> > > > Then you can guess that numpy overrides it and gives you *logical* negation of boolean values,
> > >
> > > I try to dig through the numpy source code to pinning point the overriding/monkey patching/decorating code snippets, as follows:
> > And you keep missing the point: look up numpy's *documentation* for that, not any source code.
> I find the relevant explanation here [1]:
>
> numpy.invert
> [...]
> Compute bit-wise inversion, or bit-wise NOT, element-wise.
>
> Computes the bit-wise NOT of the underlying binary representation of the integers in the input arrays. This ufunc implements the C/Python operator ~.
> [...]
> The ~ operator can be used as a shorthand for np.invert on ndarrays.
>
> x1 = np.array([True, False])
>
> ~x1
> array([False, True])
>
> [1] https://numpy.org/doc/stable/reference/generated/numpy.invert.html#numpy-invert
Or use the following commands in IPython:
import numpy as np
np.invert?
np.info(np.invert)
> HZ
More information about the Python-list
mailing list