What is the ma.masked_greater_equal() function in NumPy?

Overview

The masked_greater_equal() 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.

Syntax

This is the syntax of the masked_greater_equal() function:

ma.masked_greater_equal(x, value)
Syntax of the masked_greater_equal() function

Parameter value

The  masked_greater_equal() function takes the following parameter values:

  • x: This is the input array. It is a required parameter value.
  • value: This is the value to which elements of the array are masked if they are greater than or equal to it. It is a required parameter value.

Return value

The masked_greater_equal() function returns a masked array.

Example

# A code to illustrate the masked_greater_equal() function
# importing the necessary libraries
import numpy as np
import numpy.ma as ma
# creating an input array
my_array = np.array([1, 2, 3, 4, 5, 6, 7, 8, 9, 10])
# masking the values greater than 2
mask_array =ma.masked_greater(my_array, 2)
print(mask_array)

Explanation

  • Lines 4–5: We import the necessary library and module.
  • Line 8: We create an input array called my_array.
  • Line 11: We use the masked_greater_equal() function to mask the values greater than or equal to 2 in the input array. We assign the result to a variable called mask_array.
  • Line 13: We print the masked array, mask_array, to the console.

Free Resources