The masked_less_equal()
function in numpy.ma
(MaskedArray
class) is used to mask an array, where the value of the elements of the array is less than or equal to the specified value in the function.
Note: The
ma
in thema.masked_less_equal()
function specifies that we’re going to mask a masked array. A masked array is different from a regular array in that it has one, some, or all of its elements hidden or masked with--
. A masked array is a blend of a standardnumpy.ndarray
and a mask. When a mask is not masked, it indicates that the array under consideration has all valid values, or that it is an array of booleans that represent each value of the array under consideration, whether the value is valid or invalid.
ma.masked_less_equal(x, value)
x
: This is the input array. This is a mandatory parameter.value
: This is the value to which elements of the array are masked if they are less than or equal to it. This is a mandatory parameter.This function returns a masked array.
# importing the necessary librariesimport numpy as npimport numpy.ma as ma# creating an input arraymy_array = np.array([1, 2, 3, 4, 5, 6, 7, 8, 9, 10])# masking the values that are less than or equal to 5mask_array = ma.masked_less(my_array, 5)print(mask_array)
my_array
.masked_less_equal()
function to mask the values greater than or equal to 5
in the input array. We assign the result to the variable, mask_array
.mask_array
.