Instagram
youtube
Facebook
Twitter

Create Boolean Mask for Elements Greater Than 5

A Create Boolean Mask for Elements Greater Than 5?
Code Explanation:
Library Import: numpy is imported as np to perform array operations.
Array Creation: A NumPy array arr is created with integer elements.
Condition Check: arr > 5 compares each element in the array to 5 and returns a boolean array.
Boolean Mask: The result is stored in the variable mask, where each element is True if it’s greater than 5, otherwise False.
Display Output: print(mask) prints the boolean mask: [False True True False].

 

Program:

import numpy as np

arr = np.array([3, 6, 9, 2])

mask = arr > 5

print(mask)