  NumPy | Python Methods and Functions

`numpy.MaskedArray.masked_equal()` is used to mask an array equal to a given value.

Syntax: ` numpy.ma.masked_equal (arr, value, copy = True) `

Parameters:
arr: [ndarray] Input array which we want to mask.
copy: [bool] If True (default) make a copy of arr in the result. If False modify arr in place and return a view.

Code # 1:

 ` # Python program explaining ` ` # numpy.MaskedArray .masked_equal () method `   ` # import numy as a geek ` ` # and the numpy.ma module as ma ` ` import ` ` numpy as geek ` ` import ` ` numpy.ma as ma `   ` # create input array ` ` in_arr ` ` = ` ` geek.array ([` ` 1 ` < code class = "plain">, ` 2 ` `, ` ` 3 , - 1 , 2 ]) `` print ( "Input array:" , in_arr)   # applying MaskedArray.masked_equal methods # to enter an array where value = 2 mask_arr = ma.masked_equal (in_arr, 2 ) print ( "Masked array:" , mask_arr) `

Output :

` Input array: [1 2 3 -1 2] Masked array: [1 - 3 -1 -] `

Code # 2:

 ` # Python program explaining ` ` # numpy.MaskedArray.masked_equal () method `   ` # import numy as geek ` ` # and numpy.ma module as ma ` ` import ` ` numpy as geek ` ` import ` ` numpy.ma as ma `   ` # create input array ` ` in_arr ` ` = ` ` geek.array ([ ` ` 2e8 ` ` , ` ` 3e ` ` - ` ` 5 ` `, ` ` - ` ` 45.0 ` `, ` ` 2e5 ` `, ` ` 5e2 ` `]) ` ` print ` ` (` ` "Input array:" ` `, in_arr) `   ` # applying MaskedArray methods .masked_equal ` ` # to enter an array where value = 5e2 ` ` mask_arr = ma.masked_equal (in_arr, 5e2 ) `` print ( " Masked array: " , mask_arr) `

Output:

` Input array: [2.0e + 08 3.0e-05 -4.5e + 01 2.0e + 05 5.0e + 02] Masked array: [200000000.0 3e-05 -45.0 200000.0 -] `