0

I see this operator from time to time in different contexts. Typically, it is used in front of a numpy variable

For example:

~some_numpy_variable

samol
  • 18,950
  • 32
  • 88
  • 127
  • 3
    https://wiki.python.org/moin/BitwiseOperators – 001 Nov 13 '18 at 15:54
  • Possible duplicate of https://stackoverflow.com/questions/8305199/the-tilde-operator-in-python. – DocDriven Nov 13 '18 at 15:54
  • If called on a numpy array it calls [`numpy.invert`](https://docs.scipy.org/doc/numpy-1.14.0/reference/generated/numpy.invert.html), which computes "bit-wise inversion, or bit-wise NOT, element-wise." – Steven Rumbalski Nov 13 '18 at 15:55
  • @DeepSpace: While all those duplicates explain what bit-wise inversion is, it doesn't really explain why it work on a numpy array (which is that `~` is implemented by an object's `__invert__()` method--helpfully implemented by numpy as applying bitwise inversion to each element.) – Steven Rumbalski Nov 13 '18 at 16:06
  • Thanks everybody. This is embarrassing to have so many duplicate questions. I tried searching and googling. Something about the ~ token just did not return any results – samol Nov 13 '18 at 16:09

0 Answers0