The numpy.ma.getmask()
method in Python is used to return the mask or no mask values of a masked array. This is done by returning a Boolean array, which holds the result, of the same shape as the input array.
The ma.getmask()
method uses the syntax below:
ma.getmask(a)
The ma.getmask()
method takes a single parameter value, a
, which represents the input array (possibly masked) for which the mask is to be obtained.
The ma.getmask()
method returns an array of Boolean values indicating the mask (True
) or nomask (False
) elements of the input array.
Below, we see an example of the ma.getmask()
method:
import numpy.ma as ma# creating a masked arraya = ma.arange(8).reshape(4,2)# masking the element in the second row but the second columna[1, 1] = ma.masked# masking the elements in the third rowa[2, :] = ma.masked# implementing the ma.getmask() methodb = ma.getmask(a)print(a)print(b)
In the code above, we do the following:
numpy.ma
module.a
.ma.getmask()
function. The result is assigned to a variable, b
.a
and the obtained array, b
.