# Compute the bit-wise NOT of a One-Dimensional array element-wise in Numpy

NumpyServer Side ProgrammingProgramming

To compute the bit-wise NOT of a 1D array element-wise, 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 1d array −

arr = np.array([56, 87, 23, 92, 81, 98, 45, 98])


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 an array element-wise, use the numpy.bitwise_not() method −

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


## Example

import numpy as np

#Create a 1d array
arr = np.array([56, 87, 23, 92, 81, 98, 45, 98])

# 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 an array element-wise, use the numpy.bitwise_not() method in Python Numpy
print("\nResult (bit-wise NOT)...\n",np.bitwise_not(arr))

## Output

Array...
[56 87 23 92 81 98 45 98]

Array datatype...
int64

Array Dimensions...
1

Our Array Shape...
(8,)

Elements in the Array...
8

Result (bit-wise NOT)...
[-57 -88 -24 -93 -82 -99 -46 -99]