Can I use ~A
to invert a numpy array of booleans, instead of the rather awkward functions np.logical_and()
and np.invert()
?
Indeed, ~
seems to work fine, but I can't find it in any nympy reference manual, and - more alarmingly - it certainly does not work with scalars (e.g. bool(~True)
returns True
!), so I'm a little bit worried ...
We can also use the Tilde operator (~) also known as bitwise negation operator in computing to invert the given array. It takes the number n as binary number and “flips” all 0 bits to 1 and 1 to 0 to obtain the complement binary number.
We use numpy. linalg. inv() function to calculate the inverse of a matrix. The inverse of a matrix is such that if it is multiplied by the original matrix, it results in identity matrix.
You can flip the image vertically and horizontally by using numpy. flip() , numpy. flipud() , numpy. fliplr() .
short answer: YES
Ref:
http://docs.scipy.org/doc/numpy/reference/generated/numpy.invert.html
Notice:
Computes the bit-wise NOT of the underlying binary representation of the integers in the input arrays. This ufunc implements the C/Python operator ~.
and
bitwise_not is an alias for invert:
>> np.bitwise_not is np.invert >> True
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With