Friday, November 14, 2025
HomeLanguagesnumpy.ma.allclose() function – Python

numpy.ma.allclose() function – Python

numpy.ma.allclose() function returns True if two arrays are element-wise equal within a tolerance. This function is equivalent to allclose except that masked values are treated as equal (default) or unequal, depending on the masked_equal argument.

Syntax : numpy.ma.allclose(a, b, masked_equal = True, rtol = 1e-05, atol = 1e-08)

Parameters :
a, b : [array_like] Input arrays to compare.
masked_equal : [bool, optional] Whether masked values in a and b are considered equal (True) or not (False). They are considered equal by default.
rtol : [float, optional] Relative tolerance. The relative difference is equal to rtol * b. Default is 1e-5.
atol : [float, optional] Absolute tolerance. The absolute difference is equal to atol. Default is 1e-8.

Return : [bool] Returns True if the two arrays are equal within the given tolerance, False otherwise. If either array contains NaN, then False is returned.

Code #1 :




# Python program explaining
# numpy.ma.allclose() function
   
# importing numpy as geek 
# and numpy.ma module as ma 
import numpy as geek 
import numpy.ma as ma
    
a = geek.ma.array([1e10, 1e-8, 42.0], mask = [0, 0, 1])
  
b = geek.ma.array([1.00001e10, 1e-9, -42.0], mask = [0, 0, 1])
  
gfg = geek.ma.allclose(a, b)
  
print (gfg)


Output :

True

 
Code #2 :




# Python program explaining
# numpy.ma.allclose() function
   
# importing numpy as geek 
# and numpy.ma module as ma 
import numpy as geek 
import numpy.ma as ma
    
a = geek.ma.array([1e10, 1e-8, 42.0], mask = [0, 0, 1])
  
b = geek.ma.array([1.00001e10, 1e-9, -42.0], mask = [0, 0, 1])
  
gfg = geek.ma.allclose(a, b, masked_equal = False)
  
print (gfg)


Output :

False
Dominic
Dominichttp://wardslaus.com
infosec,malicious & dos attacks generator, boot rom exploit philanthropist , wild hacker , game developer,
RELATED ARTICLES

Most Popular

Dominic
32399 POSTS0 COMMENTS
Milvus
95 POSTS0 COMMENTS
Nango Kala
6765 POSTS0 COMMENTS
Nicole Veronica
11917 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11984 POSTS0 COMMENTS
Shaida Kate Naidoo
6889 POSTS0 COMMENTS
Ted Musemwa
7141 POSTS0 COMMENTS
Thapelo Manthata
6837 POSTS0 COMMENTS
Umr Jansen
6839 POSTS0 COMMENTS