What is the numpy.ma.getmask() function in Python?
Overview
Python’s ma.getmask() function returns the mask of a masked array (i.e, the nomask).
Syntax
ma.getmask(a)
Parameter value
The ma.getmask() function takes the a value as a parameter. This represents an input MaskedArray for which the mask is required.
Return value
The ma.getmask() function returns an array of Boolean values indicating which input array elements are nomask or mask. It returns True if the element is mask and False if the element is nomask.
Example
import numpy as npimport numpy.ma as ma# creating a MaskedArray with the element 3 as the maskmyarray = ma.masked_equal([[1,2],[3,4]], 3)# implementing the ma.getmask() functionnewarray = ma.getmask(myarray)print(newarray)
Explanation
- Line 1-2: We import the required module and library.
- Line 5: We create a MaskedArray،
myarray، which has its element3as themask. - Line 8: We implement the
ma.getmask()function on the input MaskedArray. The result is assigned to a variablenewarray. - Line 10: We print the variable،
newarray.