The masked_greater()
function in NumPy is used to mask an array, where the value of the element of the array is greater than the specified value in the function.
ma.masked_greater(x, value)
This function takes the following parameter values:
x
: This is the input array. This is a required parameter.value
This is the value to which elements of the array are masked if they are greater. This is a required parameter.This function returns a masked array.
# A code to illustrate the masked_greater() function# 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 greater than 2mask_array =ma.masked_greater(my_array, 2)print(mask_array)
my_array
.2
in the input array using the masked_greater()
function. The result is assigned to a variable, mask_array
.mask_array
.