Friday, September 5, 2025
HomeLanguagesnumpy.real_if_close() function – Python

numpy.real_if_close() function – Python

In this numpy.real_if_close()function, if complex input returns a real array then complex parts are close to zero.

Syntax : numpy.real_if_close(arr, tol = 100)

Parameters :
arr : [array_like] Input array.
tol : [float] “Close to zero” is defined as tol. Tolerance in machine epsilons for the complex part of the elements in the array.

Return : [ndarray] If arr is real, the type of arr is used for the output. If arr has complex elements, the returned type is float.

Code #1 :




# Python program explaining
# numpy.real_if_close() function
       
# importing numpy as geek 
import numpy as geek 
   
arr = [3.6 + 4e-14j]
tol = 1000
   
gfg = geek.real_if_close(arr, tol)
  
print (gfg)


Output :

[3.6]

 
Code #2 :




# Python program explaining
# numpy.real_if_close() function
       
# importing numpy as geek 
import numpy as geek 
   
arr = [3.6 + 2e-11j]
tol = 1000
   
gfg = geek.real_if_close(arr, tol)
  
print (gfg)


Output :

[3.6+2.e-11j]
Dominic
Dominichttp://wardslaus.com
infosec,malicious & dos attacks generator, boot rom exploit philanthropist , wild hacker , game developer,
RELATED ARTICLES

Most Popular

Dominic
32265 POSTS0 COMMENTS
Milvus
81 POSTS0 COMMENTS
Nango Kala
6634 POSTS0 COMMENTS
Nicole Veronica
11801 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11863 POSTS0 COMMENTS
Shaida Kate Naidoo
6752 POSTS0 COMMENTS
Ted Musemwa
7025 POSTS0 COMMENTS
Thapelo Manthata
6701 POSTS0 COMMENTS
Umr Jansen
6718 POSTS0 COMMENTS