Numpy MaskedArray.allequal() function | Python
In many circumstances, datasets can be incomplete or tainted by the presence of invalid data. For example, a sensor may have failed to record a data, or recorded an invalid value. The
numpy.ma module provides a convenient way to address this issue, by introducing masked arrays.Masked arrays are arrays that may have missing or invalid entries.
numpy.MaskedArray.allequal() function return True if all entries of a and b are equal, using fill_value as a truth value where either or both are masked.
Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.
To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course. And to begin with your Machine Learning Journey, join the Machine Learning - Basic Level Course
numpy.ma.allequal(arr1, arr2, fill_value=True)
arr1, arr2 : [array_like] Input arrays to compare.
fill_value : [ bool, optional] Whether masked values in arr1 or arr2 are considered equal (True) or not (False).
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 :
1st Input array : [ 1.0e+08 1.0e-05 -1.5e+01] 1st Masked array : [100000000.0 1e-05 --] 2nd Input array : [1.0e+08 1.0e-05 1.5e+01] 2nd Masked array : [100000000.0 1e-05 --] Output array : False
Code #2 :
1st Input array : [ 2.0e+08 3.0e-05 -4.5e+01] 1st Masked array : [200000000.0 3e-05 --] 2nd Input array : [2.0e+08 3.0e-05 1.5e+01] 2nd Masked array : [200000000.0 3e-05 --] Output array : True