- Trending Categories
- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP

- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who

# Mask array elements greater than or equal to a given value in Numpy

To mask an array where greater than equal to a given value, use the **numpy.ma.masked_greater_equal()** method in Python Numpy. This function is a shortcut to masked_where, with condition = (x >= value).

A masked array is the combination of a standard numpy.ndarray and a mask. A mask is either nomask, indicating that no value of the associated array is invalid, or an array of booleans that determines for each element of the associated array whether the value is valid or not.

## Steps

At first, import the required library −

import numpy as np import numpy.ma as ma

Create an array with int elements using the numpy.array() method −

arr = np.array([[83, 55, 91], [90, 49, 39], [73, 83, 51], [82, 45, 67]]) print("Array...\n", arr)

Get the type pf array −

print("\nArray type...\n", arr.dtype)

Get the dimensions of the Array −

print("\nArray Dimensions...\n",arr.ndim)

Get the shape of the Array −

print("\nOur Array Shape...\n",arr.shape)

Get the number of elements of the Array −

print("\nNumber of Elements in the Array...\n",arr.size)

To mask an array where greater than equal to a given value, use the numpy.ma.masked_greater_equal() method. Here, we will the array greater than equal to value 83 −

print("\nResult...\n",np.ma.masked_greater_equal(arr, 83))

## Example

import numpy as np import numpy.ma as ma # Create an array with int elements using the numpy.array() method arr = np.array([[83, 55, 91], [90, 49, 39], [73, 83, 51], [82, 45, 67]]) print("Array...\n", arr) # Get the type pf array print("\nArray type...\n", arr.dtype) # Get the dimensions of the Array print("\nArray Dimensions...\n",arr.ndim) # Get the shape of the Array print("\nOur Array Shape...\n",arr.shape) # Get the number of elements of the Array print("\nNumber of Elements in the Array...\n",arr.size) # To mask an array where greater than equal to a given value, use the numpy.ma.masked_greater_equal() method in Python Numpy # Here, we will the array greater than equal to value 83 print("\nResult...\n",np.ma.masked_greater_equal(arr, 83))

## Output

Array... [[83 55 91] [90 49 39] [73 83 51] [82 45 67]] Array type... int64 Array Dimensions... 2 Our Array Shape... (4, 3) Number of Elements in the Array... 12 Result... [[-- 55 --] [-- 49 39] [73 -- 51] [82 45 67]]

- Related Questions & Answers
- Mask array elements greater than a given value in Numpy
- Mask array elements equal to a given value in Numpy
- Mask an array where less than or equal to a given value in Numpy
- Mask array elements less than a given value in Numpy
- Mask array elements not equal to a given value in Numpy
- Check which element in a masked array is greater than or equal to a given value in NumPy
- Count elements less than or equal to a given value in a sorted rotated array in C++
- Check which element in a masked array is less than or equal to a given value in Numpy
- Return the truth value of an array greater than equal to another element-wise in Numpy
- How to find numbers in an array that are greater than, less than, or equal to a value in java?
- Mask an array where the data is exactly equal to value in Numpy
- How to check if the elements of a series object are Greater Than or Equal to scalar value?
- Compare and return True if a Numpy array is greater than equal to another
- Adding elements of an array until every element becomes greater than or equal to k in C++.
- Program to find X for special array with X elements greater than or equal X in Python