Ravi Vishwakarma is a dedicated Software Developer with a passion for crafting efficient and innovative solutions. With a keen eye for detail and years of experience, he excels in developing robust software systems that meet client needs. His expertise spans across multiple programming languages and technologies, making him a valuable asset in any software development project.
ICSM Computer
23-Nov-2025To filter (select) values from a NumPy array, you use boolean indexing — create a boolean condition and apply it to the array.
Basic Example
Output
Filter Using Multiple Conditions
Use
&(AND),|(OR), and~(NOT).Parentheses are required.
Output:
Filter with Another Array of Booleans
Output:
Filter Strings
To filter strings containing a substring:
Filter 2D Arrays
Output:
Replace filtered values instead of selecting
Output:
Get indexes of matches
Result:
Summary
arr[arr > 3]arr[(arr >= 10) & (arr <= 20)]arr[mask]arr[arr > 10] = 0np.where(arr == x)