# Compute the bit-wise NOT of a boolean array in Numpy

NumpyServer Side ProgrammingProgramming

#### Python Data Science basics with Numpy, Pandas and Matplotlib

Most Popular

63 Lectures 6 hours

#### Data Analysis using NumPy and Pandas

19 Lectures 8 hours

#### Numpy with Python

Most Popular

12 Lectures 3 hours

To compute the bit-wise NOT of a boolean array, use the numpy.bitwise_not() method in Python Numpy. 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 where parameter is the condition broadcast over the input. At locations where the condition is True, the out array will be set to the ufunc result. Elsewhere, the out array will retain its original value. Note that if an uninitialized out array is created via the default out=None, locations within it where the condition is False will remain uninitialized.

## Steps

At first, import the required library −

import numpy as np

Create a 2d array −

arr = np.array([[True, False], [False,True ], [False, False]])


Displaying our array −

print("Array...\n",arr)

Get the datatype −

print("\nArray datatype...\n",arr.dtype)


Get the dimensions of the Array −

print("\nArray Dimensions...\n",arr.ndim)

Get the shape of the Array −

print("\nOur Array Shape...\n",arr.shape)


Get the number of elements of the Array −

print("\nElements in the Array...\n",arr.size)

To compute the bit-wise NOT of a boolean array, use the numpy.bitwise_not() method in Python Numpy −

print("\nResult (bit-wise NOT)...\n",np.bitwise_not(arr))


## Example

import numpy as np

# Create a 2d array
arr = np.array([[True, False], [False,True ], [False, False]])

# Displaying our array
print("Array...\n",arr)

# Get the datatype
print("\nArray datatype...\n",arr.dtype)

# Get the dimensions of the Array
print("\nArray Dimensions...\n",arr.ndim)

# Get the shape of the Array
print("\nOur Array Shape...\n",arr.shape)

# Get the number of elements of the Array
print("\nElements in the Array...\n",arr.size)

# To compute the bit-wise NOT of a boolean array, use the numpy.bitwise_not() method in Python Numpy
print("\nResult (bit-wise NOT)...\n",np.bitwise_not(arr))

## Output

Array...
[[ True False]
[False True]
[False False]]

Array datatype...
bool

Array Dimensions...
2

Our Array Shape...
(3, 2)

Elements in the Array...
6

Result (bit-wise NOT)...
[[False True]
[ True False]
[ True True]]