You can use numpy.extract:

>>> nparr = np.array([1, 2, 3, 4, 5, 6, 7, 8, 9, 10])
>>> nparreven = np.extract(nparr % 2 == 0, nparr)

or numpy.where:

>>> nparr = np.array([1, 2, 3, 4, 5, 6, 7, 8, 9, 10])
>>> nparreven = nparr[np.where(nparr % 2 == 0)]
Answer from unlut on Stack Overflow
🌐
W3Schools
w3schools.com › python › numpy › numpy_array_filter.asp
NumPy Filter Array
import numpy as np arr = np.array([1, 2, 3, 4, 5, 6, 7]) # Create an empty list filter_arr = [] # go through each element in arr for element in arr: # if the element is completely divisble by 2, set the value to True, otherwise False if element % 2 == 0: filter_arr.append(True) else: filter_arr.append(False) newarr = arr[filter_arr] print(filter_arr) print(newarr) Try it Yourself » · The above example is quite a common task in NumPy and NumPy provides a nice way to tackle it. We can directly substitute the array instead of the iterable variable in our condition and it will work just as we expect it to.
🌐
DataCamp
datacamp.com › doc › numpy › filtering-arrays
NumPy Filtering Arrays
In this syntax, condition is a boolean array that determines which elements from array are included in filtered_array. import numpy as np array = np.array([1, 2, 3, 4, 5]) condition = array > 3 filtered_array = array[condition] print(filtered_array) # Output: [4, 5]
🌐
GeeksforGeeks
geeksforgeeks.org › python › numpy-filtering-rows-by-multiple-conditions
NumPy - Filtering rows by multiple conditions - GeeksforGeeks
October 10, 2022 - # importing numpy lib import numpy as np # making a numpy array arr = np.array([x for x in range(11, 40)]) print("Original array") print(arr) # making a blank list new_arr = [] for x in arr: # applying two conditions: number is divisible by 2 and is greater than 15 if x % 2 == 0 and x > 15: new_arr.append(x) # Converting new list into numpy array new_arr = np.array(new_arr) print("New array") print(new_arr) ... # importing numpy lib import numpy as np # making a numpy array arr = np.array([x for x in range(11, 40)]) print("Original array") print(arr) # using lambda to apply condition new_arr = list(filter(lambda x: x > 15 and x % 2 == 0 and x % 10 != 0, arr)) # Converting new list into numpy array new_arr = np.array(new_arr) print("New array") print(new_arr)
🌐
GeeksforGeeks
geeksforgeeks.org › python › how-to-filter-two-dimensional-numpy-array-based-on-condition
How to filter two-dimensional NumPy array based on condition ? - GeeksforGeeks
July 23, 2025 - To filter we used this fltr in numpy.in1d() method and stored as its values in the original array that return True if condition fulfills.
🌐
Python Guides
pythonguides.com › python-numpy-filter
How To Filter NumPy 2D Array By Condition In Python
May 16, 2025 - Boolean indexing is the easiest way to filter a 2D array in Python NumPy. It works by creating a mask of True/False values and using it to select elements. Let’s create a simple 2D array representing sales data for different store locations:
🌐
ProjectPro
projectpro.io › recipes › filter-numpy-array-based-on-two-or-more-conditions
How to filter a numpy array based on two or more conditions? -
May 25, 2022 - Here we can see the array has been filtered, as we have pass a condition where if the values are than "65" append that values and exclude the values which are less than "65".
🌐
EyeHunts
tutorial.eyehunts.com › home › numpy filter array by condition | example code
NumPy filter array by condition | Example code
May 16, 2022 - ... import numpy as np na = ... = na[np.where(na % 2 == 0)] print(res) ... Answer: Use boolean indexing to filter elements in an array by value to filter NumPy Array....
Find elsewhere
🌐
Sling Academy
slingacademy.com › article › numpy-how-to-filter-an-array-by-a-condition
NumPy: How to Filter an Array by a Condition - Sling Academy
At its simplest, filtering can be done with comparison operators. When you perform a comparison operation on an array, you get a boolean array that you can use to select elements. import numpy as np # Create a NumPy array arr = np.array([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) # Condition for filtering ...
🌐
Llego
llego.dev › home › blog › numpy: filtering data with where() and extract()
NumPy: Filtering Data with where() and extract() - llego.dev
March 16, 2023 - The main benefits of using NumPy’s ... two different approaches for filtering. where() returns a new array containing filtered values, while extract() returns the filtered values directly....
🌐
NumPy
numpy.org › doc › 2.2 › reference › generated › numpy.where.html
numpy.where — NumPy v2.2 Manual
>>> np.where([[True, False], [True, True]], ... [[1, 2], [3, 4]], ... [[9, 8], [7, 6]]) array([[1, 8], [3, 4]]) The shapes of x, y, and the condition are broadcast together:
🌐
Statology
statology.org › home › how to filter a numpy array (4 examples)
How to Filter a NumPy Array (4 Examples)
July 9, 2022 - by Zach Bobbitt Last updated on Last updated on July 9, 2022 · You can use the following methods to filter the values in a NumPy array: Method 1: Filter Values Based on One Condition · #filter for values less than 5 my_array[my_array < 5] ...
🌐
Data Science Parichay
datascienceparichay.com › home › blog › filter a numpy array – with examples
Filter a Numpy Array - With Examples - Data Science Parichay
June 17, 2022 - You can filter a numpy array by creating a list or an array of boolean values indicative of whether or not to keep the element in the corresponding array. This method is called boolean mask slicing.
🌐
TutorialsPoint
tutorialspoint.com › numpy › numpy_filtering_arrays.htm
NumPy - Filtering Arrays
In the following example, we are filtering elements greater than the value "10" from the given array − · import numpy as np # Creating an array array = np.array([1, 5, 8, 12, 20, 3]) # Define the condition condition = array > 10 # Apply the condition to filter the array filtered_array = array[condition] print("Original Array:", array) print("Filtered Array (elements > 10):", filtered_array)
🌐
Medium
mr-amit.medium.com › how-to-filter-data-in-numpy-79b6ca4eaff7
How to Filter Data in NumPy?. “Data is like gold — it’s valuable, but… | by It's Amit | Medium
March 6, 2025 - Filtering with Multiple Conditions ... 30]) # Filter: Get values greater than 15 and less than 30 filtered_data = data[(data > 15) & (data < 30)] print(filtered_data) # Output: [20 25]...
🌐
Codecademy
codecademy.com › learn › introduction-to-numpy-for-finance › modules › learn-numpy-introduction-for-finance › cheatsheet
Introduction to NumPy: Learn NumPy: Introduction Cheatsheet | Codecademy
Level up in financial analytics by learning Python to process, analyze, and visualize financial data. ... NumPy elements can be indexed using conditionals. The syntax to filter an array using a conditional is array_name[conditional].
🌐
Delft Stack
delftstack.com › home › howto › numpy › numpy filter elements in array
How to Filter Elements in a NumPy Array | Delft Stack
February 2, 2024 - condition - It is the boolean condition for which each element of the array is checked. x - It is a value given to elements satisfying the condition or a computation carried on the satisfying elements. y - It is a value given to elements not ...
🌐
NumPy
numpy.org › doc › stable › reference › generated › numpy.where.html
numpy.where — NumPy v2.5 Manual
>>> np.where([[True, False], [True, True]], ... [[1, 2], [3, 4]], ... [[9, 8], [7, 6]]) array([[1, 8], [3, 4]]) The shapes of x, y, and the condition are broadcast together:
🌐
Arab Psychology
scales.arabpsychology.com › home › how to easily filter numpy arrays: a step-by-step guide
How To Easily Filter NumPy Arrays: A Step-by-Step Guide
November 29, 2025 - You can use the following methods to filter the values in a NumPy array: ... This is the most straightforward technique, utilizing direct Boolean comparison to select elements. The expression returns a Boolean array, which is then used as an index to filter the original array, keeping only those elements where the condition evaluated to True.
🌐
Dataquest
support.dataquest.io › en › articles › 812-filter-data-like-a-pro-with-this-simple-numpy-trick
Filter Data Like a Pro with This Simple NumPy Trick | DATAQUEST
May 19, 2026 - Searching for patterns or anomalies in big datasets can be tricky, but NumPy's Boolean indexing makes it simple. With this powerful technique, you can filter data intuitively using conditions—no loops required.