Friday, January 16, 2026
HomeLanguagesnumpy.reciprocal() in Python

numpy.reciprocal() in Python

The numpy.reciprocal() is a mathematical function that is used to calculate reciprocal of all the elements in the input array.

Syntax :numpy.reciprocal(x, /, out=None, *, where=True)
Parameters :

x[array_like]: Input array or object whose elements needed to test.

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 to pass keyword variable length of argument to a function. 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 :
y : ndarray. This is a scalar if x is a scalar.

Note: For integer arguments with absolute value larger than 1, the result is always zero because of the way Python handles integer division. For integer zero the result is an overflow.

Code #1 :




# Python3 code demonstrate reciprocal() function
  
# importing numpy
import numpy as np
  
in_num = 2.0
print ("Input  number : ", in_num)
  
out_num = np.reciprocal(in_num)
print ("Output number : ", out_num)


Output :

Input  number :  2.0
Output number :  0.5

 
Code #2 :




# Python3 code demonstrate reciprocal() function
  
# importing numpy
import numpy as np
  
in_arr = [2., 3., 8.
print ("Input array : ", in_arr) 
    
out_arr = np.reciprocal(in_arr) 
print ("Output array : ", out_arr) 


Output :

Input array :  [2.0, 3.0, 8.0]
Output array :  [ 0.5         0.33333333  0.125     ]

 
Code #3 : Exception in reciprocal() function. Result is always zero.




# Python3 code demonstrate Exception in reciprocal() function
  
# importing numpy
import numpy as np
  
in_arr = [2, 3, 8
print ("Input array : ", in_arr) 
    
out_arr = np.reciprocal(in_arr) 
print ("Output array : ", out_arr) 


Output :

Input array :  [2, 3, 8]
Output array :  [0 0 0]
RELATED ARTICLES

1 COMMENT

Most Popular

Dominic
32474 POSTS0 COMMENTS
Milvus
117 POSTS0 COMMENTS
Nango Kala
6846 POSTS0 COMMENTS
Nicole Veronica
11977 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12062 POSTS0 COMMENTS
Shaida Kate Naidoo
6985 POSTS0 COMMENTS
Ted Musemwa
7219 POSTS0 COMMENTS
Thapelo Manthata
6933 POSTS0 COMMENTS
Umr Jansen
6911 POSTS0 COMMENTS