Hi all,

So basically my requirement is pretty simple. I just wanted to know I could make use of the tilde operator (~) to invert a Numpy array consisting of boolean data. However, I am aware of the standard way to do it is to use the functions np.invert() and even np.logical_and()

Tilde seems to work but my concern here is that I am unable to find the plausible usage in any Numpy reference material, to be honest.

Note: I have seen that it does not work with scalars at all. Well this is what I mean, consider this example:
Example: bool(~True) -----> This returns True.

Appreciate all the help! Jan 11, 2019 in Python 3,281 views

Good question, glad you brought this up.

I have actually worked on it personally and I can assure you it is possible by all means.

But, to give you more clarity I would like you to actually check out the official Numpy documentation under "numpy.invert".

This documentation answers your question perfectly. But, it is important that you do note this.

The bitwise_not is an alias for the invert method:

Check out the tiny snippet I have here:

>> np.bitwise_not is np.invert
>> True

And, here is where the Bit-wise NOT operator of the binary representation of the integers are present in the array input. So, how do we go about it from here?

Well the ufunc implements the Python Operator Tilde (~).

Perfect, right? Hope this helped! answered Jan 11, 2019 by
• 3,540 points

Is it possible to print all the modules imported in a python script?

Since I am using Python 3.6, I ...READ MORE

Is it possible to create an array with all values as zero in python?

You can use  np.zeros(4,3) This will create a 4 ...READ MORE

Doubt in numpy.vstack

The vstack function in numpy will stack ...READ MORE

Count the digits in a Numpy array

Hey, @Sourav, We can solve this with the ...READ MORE

How to save numpy array?

Hi@akhtar, You can use numpy.save() function to save ...READ MORE

+1 vote

View onto a numpy array?

just index it as you normally would. ...READ MORE