  # Numpy MaskedArray.allequal () Function | python

Arrays | NumPy | Python Methods and Functions

`numpy.MaskedArray.allequal()` returns True if all records a and b are equal, using fill_value as truth value, where one or both are masked.

Syntax: ` numpy.ma.allequal (arr1, arr2, fill_value = True) `

Parameters:
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:

` `

` # Python program explaining # numpy.MaskedArray.allequal () method    # import numy as geek # and numpy.ma module as ma import numpy as geek import numpy.ma as ma   # create the first input array in_arr1 = geek.array ([ 1e8 , 1e   - 5 , - 15.0 ]) print ( "1st Input array:" , in_arr1)   # We now create the first masked array, invalidating the third entry. mask_arr1 = ma.masked_array (in_arr1, mask = [ 0 , 0 , 1 ]) print ( "1st Masked array:" , mask_arr1)    # create a second input array in_arr2 = geek.array ([ 1e8 , 1e - 5 , 15.0 ]) print ( "2nd Input array: " , in_arr2)    # We now create a 2nd masked array, invalidating the third entry. mask_arr2 = ma.masked_array (in_arr2, mask = [ 0 , 0 , 1 ]) print ( "2nd Masked array:" , mask_arr2)   # applying the MaskedArray.allequal method out_arr = ma.allequal (mask_arr1, mask_arr2, fill_value = False ) print ( "Output array:" , out_arr) `

` ` Output:

` 1st Input array: [1.0 e + 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:

 ` # import numy as a geek ` ` # and the numpy.ma module as ma ` ` import ` ` numpy as geek ` ` import ` ` numpy.ma as ma ` ` `  ` # create the first input array ` ` in_arr1 ` ` = ` ` geek.array ([` ` 2e8 ` `, ` ` 3e ` ` - ` ` 5 ` `, ` ` - ` ` 45.0 ` `]) ` ` print ` ` (` ` "1st Input array:" ` `, in_arr1) ` ` `  ` # We now create the first masked array, invalidating the third entry. ` ` mask_arr1 ` ` = ` ` ma.masked_array (in_arr1, mask ` ` = ` ` [` ` 0 ` `, ` ` 0 ` `, ` ` 1 ` `]) ` ` print ` ` (` ` "1st Masked array:" ` `, mask_arr1) ` ` `  ` # create a second input array ` ` in_arr2 ` ` = ` ` geek.array ( [` ` 2e8 ` `, ` ` 3e ` ` - ` ` 5 ` `, ` ` 15.0 ` `]) ` ` print ` ` (` ` "2nd Input array:" ` `, in_arr2) `   ` # We now create a 2nd masked array, invalidating the third entry. ` ` mask_arr2 ` ` = ` ` ma.masked_array (in_arr2, mask ` ` = ` ` [` ` 0 ` `, ` ` 0 ` `, ` ` 1 ` `]) ` ` print ` ` (` `" 2nd Masked array: "` `, mask_arr2) ` ` # applying the MaskedArray.allequal method ` ` out_arr ` ` = ` ` ma.allequal (mask_arr1, mask_arr2, fill_value ` ` = ` ` True ` `) ` ` print ` ` (` ` "Output array:" ` `, out_arr) `

Output :

` 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 `