Use a list comprehension:
[y for x,y in A if x>2]
Demo:
>>> A=[(1,'A'),(2,'H'),(3,'K'),(4,'J')]
>>> [y for x,y in A if x>2]
['K', 'J']
>>>
Answer from U13-Forward on Stack OverflowW3Schools
w3schools.com โบ python โบ numpy โบ numpy_array_filter.asp
NumPy Filter Array
A boolean index list is a list of booleans corresponding to indexes in the array. If the value at an index is True that element is contained in the filtered array, if the value at that index is False that element is excluded from the filtered array.
08:11
Filtering in NumPy is easy! ๐งฒ - YouTube
17:21
How to Filter Data in Python Pandas with Multiple Conditions ...
18:50
MASTERING Python's FILTER Function is Easier Than You Think! - YouTube
18:20
Python Filter List - The Easiest Methods - YouTube
06:52
NumPy Filter Array | Filter a NumPy Array | Filter rows of a NumPy ...
10:11
Python NumPy Tutorial For Beginners - How to Filter a NumPy Array ...
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.
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)
Mimo
mimo.org โบ glossary โบ python โบ filter
Python filter(): Syntax, Usage, and Examples
You should reach for filter() when you want to streamline conditional selection. It's especially useful for: Keeping only valid data entries from a list or array ... Instead of managing temporary lists and for loops manually, you express your filtering logic in one line. This approach is similar to filtering in other languages like Java or SQL, but with Python's more concise syntax.
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:
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.
EyeHunts
tutorial.eyehunts.com โบ home โบ python filter list by condition
Python filter list by condition - Tutorial - By EyeHunts
January 13, 2023 - numbers = [25, 24, 26, 45, 25, 23, 50, 51] filtred = list(filter(lambda x: x > 25, numbers)) print(filtred) print(type(filtred)) ... Another way is to create an empty list, iterate through the current list and append all relevant items to the new list, like so: numbers = [25, 24, 26, 45, 25, 23, 50, 51] new_list = [] for i in numbers: if 25 <= i <= 50: new_list.append(i) print(new_list) Do comment if you have any doubts or suggestions on this Python filter topic.
Top answer 1 of 2
15
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)]
2 of 2
8
Since you don't provide an example data, use toy data:
# Cost of agents represented by indices of cost, we have agents 0, 1, 2, 3
cost = np.array([4,5,6,2])
# Agents to consider
np_agents = np.array([0,1,3])
# threshold for each agent. Calculate different thresholds for different agents. Use array of indexes np_agents into cost array.
thresholds = cost[np_agents] # np.array([4,5,2])
feasible_agents = np_agents[np_agents > thresholds] # np.array([3])
GeeksforGeeks
geeksforgeeks.org โบ python โบ filter-in-python
filter() in python - GeeksforGeeks
filter() function is used to extract elements from an iterable (like a list, tuple or set) that satisfy a given condition. It works by applying a function to each element and keeping only those for which function returns True.
Published: March 18, 2026
KDnuggets
kdnuggets.com โบ 2022 โบ 11 โบ 5-ways-filtering-python-lists.html
5 Ways of Filtering Python Lists - KDnuggets
November 14, 2022 - It is easy to write, and you can even add multiple if-else conditions without an issue. Learn list comprehension with code examples by reading When to Use a List Comprehension in Python. scores = [200, 105, 18, 80, 150, 140] filtered_scores = [s for s in scores if s >= 150] print(filtered_scores)
TutorialsPoint
tutorialspoint.com โบ numpy โบ numpy_filtering_arrays.htm
NumPy - Filtering Arrays
Boolean indexing allows you to filter array elements based on conditions. By applying a condition to an array, you obtain a Boolean array that you can use to index the original array.