Thursday, October 2, 2025
HomeLanguagesnumpy.invert() in Python

numpy.invert() in Python

numpy.invert() function is used to Compute the bit-wise Inversion of an array element-wise. It computes the bit-wise NOT of the underlying binary representation of the integers in the input arrays.

For signed integer inputs, the two’s complement is returned. In a two’s-complement system negative numbers are represented by the two’s complement of the absolute value.

Syntax : numpy.invert(x, /, out=None, *, where=True, casting=’same_kind’, order=’K’, dtype=None, ufunc ‘invert’)

Parameters :
x : [array_like] Input array.
out : [ndarray, optional] A location into which the result is stored. If provided, it must have a shape that the inputs broadcast to. If not provided or None, a freshly-allocated array is returned.
**kwargs : Allows you to pass keyword variable length of argument to a function. It is used when we want to handle named argument in a function.
where : [array_like, optional] True value means to calculate the universal functions(ufunc) at that position, False value means to leave the value in the output alone.

Return : [ndarray or scalar] Result. This is a scalar if x is scalar.

Code #1 : Working




# Python program explaining
# invert() function
  
import numpy as geek
in_num = 10
print ("Input  number : ", in_num)
    
out_num = geek.invert(in_num) 
print ("inversion of 10 : ", out_num) 


Output :

Input  number :  10
inversion of 10 :  -11

 
Code #2 :




# Python program explaining
# invert() function
  
import numpy as geek
  
in_arr = [2, 0, 25]
print ("Input array : ", in_arr)
    
out_arr = geek.invert(in_arr) 
print ("Output array after inversion: ", out_arr) 


Output :

Input array :  [2, 0, 25]
Output array after inversion:  [ -3  -1 -26]

 
Code #3 :




# Python program explaining
# invert() function
  
import numpy as geek
  
in_arr = [True, False]
print("Input array : ", in_arr) 
  
    
out_arr = geek.invert(in_arr) 
print ("Output array after inversion: ", out_arr) 


Output :

Input array :  [True, False]
Output array after inversion:  [False  True]
RELATED ARTICLES

Most Popular

Dominic
32330 POSTS0 COMMENTS
Milvus
84 POSTS0 COMMENTS
Nango Kala
6703 POSTS0 COMMENTS
Nicole Veronica
11867 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11926 POSTS0 COMMENTS
Shaida Kate Naidoo
6816 POSTS0 COMMENTS
Ted Musemwa
7078 POSTS0 COMMENTS
Thapelo Manthata
6775 POSTS0 COMMENTS
Umr Jansen
6774 POSTS0 COMMENTS