>>> a = np.array([[1,2,3,4],[5,6,7,8],[9,10,11,12]])
>>> a
array([[ 1,  2,  3,  4],
       [ 5,  6,  7,  8],
       [ 9, 10, 11, 12]])

>>> a[a[:,0] > 3] # select rows where first column is greater than 3
array([[ 5,  6,  7,  8],
       [ 9, 10, 11, 12]])

>>> a[a[:,0] > 3][:,np.array([True, True, False, True])] # select columns
array([[ 5,  6,  8],
       [ 9, 10, 12]])

# fancier equivalent of the previous
>>> a[np.ix_(a[:,0] > 3, np.array([True, True, False, True]))]
array([[ 5,  6,  8],
       [ 9, 10, 12]])

For an explanation of the obscure np.ix_(), see https://stackoverflow.com/a/13599843/4323

Finally, we can simplify by giving the list of column numbers instead of the tedious boolean mask:

>>> a[np.ix_(a[:,0] > 3, (0,1,3))]
array([[ 5,  6,  8],
       [ 9, 10, 12]])
Answer from John Zwinck on Stack Overflow
🌐
ProjectPro
projectpro.io › recipes › select-elements-from-numpy-array-in-python
How to Select Columns in NumPy Array using np.select? -
February 22, 2024 - You can use array slicing with a specified column index. ... The expression arr[:, 1:3] selects all rows (indicated by :) and the second and third columns (columns with index 1 and 2).
Discussions

python - Extracting specific columns in numpy array by condition - Stack Overflow
In Python, the expression -0.4 ... by converting it into a bool. Unlike Python lists and tuples, numpy arrays do not support the conversion. The correct way to specify the condition is with bitwise & (which is unambiguous and non-short-circuiting), rather than the implicit and (which short circuits and is ambiguous in this case): condition = ((x_y_z[2, :] > - 0.4) & (x_y_z[2, :] < 0.1)) condition is a boolean mask that selects the columns you ... More on stackoverflow.com
🌐 stackoverflow.com
April 4, 2019
python - Numpy select rows based on condition - Stack Overflow
I want to remove rows from a two dimensional numpy array using a condition on the values of the first row. I am able to do this with regular python using two loops, but I would like to do it more More on stackoverflow.com
🌐 stackoverflow.com
numpy - Selecting rows if column values meet certain condition - Stack Overflow
Find the answer to your question by asking. Ask question ... See similar questions with these tags. ... 7 VisibleDeprecationWarning: boolean index did not match indexed array along dimension 1; dimension is 2 but corresponding boolean dimension is 1 · 27 Select certain rows (condition met), but only some columns in Python/Numpy... More on stackoverflow.com
🌐 stackoverflow.com
May 2, 2017
python - Numpy Select with Multiple Conditions Not Returning Values - Stack Overflow
I combined three dataframes that have multiple email columns, then renamed the columns for ease of scripting. I'm trying to create a master email column based on conditions. If C is populated, use ... More on stackoverflow.com
🌐 stackoverflow.com
🌐
w3tutorials
w3tutorials.net › blog › select-certain-rows-condition-met-but-only-some-columns-in-python-numpy
How to Select Specific Rows (with Condition) and Columns in Python NumPy — w3tutorials.net
NumPy uses 0-based indexing (the first element is at index 0). Basic indexing lets you select rows/columns by their position using array[row_index, column_index].
Find elsewhere
🌐
Finxter
blog.finxter.com › home › learn python blog › conditional indexing: how to conditionally select elements in a numpy array?
Conditional Indexing: How to Conditionally Select Elements in a NumPy Array? - Be on the Right Side of Change
April 10, 2021 - Normal slicing such as a[i:j] would ... (also: conditional indexing) allows you to carve out an arbitrary combination of elements from the NumPy array by defining a Boolean array with the same shape....
🌐
Codepointtech
codepointtech.com › home › how to select columns based on condition in pandas
How to Select Columns Based on Condition in Pandas - codepointtech.com
January 17, 2026 - Targeted Analysis: Focus on columns that meet specific criteria, like all columns containing “ID” in their name or columns where all values are unique. First, let”s ensure we have Pandas imported and a sample DataFrame to work with. This DataFrame will serve as our playground for demonstrating different selection techniques. import pandas as pd import numpy as np # Create a sample DataFrame data = { "CustomerID": [1, 2, 3, 4, 5], "Age": [25, 30, 35, 40, 45], "Income": [50000, 60000, 75000, 80000, 90000], "ProductA_Sales": [10, 15, 12, np.nan, 20], "ProductB_Sales": [5, 8, 7, 10, 11], "City": ["New York", "Los Angeles", "Chicago", "Houston", "Phoenix"], "IsActive": [True, False, True, True, False], "Order_ID": ["ORD001", "ORD002", "ORD003", "ORD004", "ORD005"] } df = pd.DataFrame(data) print(df)
🌐
NumPy
numpy.org › doc › 1.25 › reference › generated › numpy.select.html
numpy.select — NumPy v1.25 Manual
Return elements from one of two arrays depending on condition. ... >>> x = np.arange(6) >>> condlist = [x<3, x>3] >>> choicelist = [x, x**2] >>> np.select(condlist, choicelist, 42) array([ 0, 1, 2, 42, 16, 25])
🌐
Towards Data Science
towardsdatascience.com › home › artificial intelligence › the difference between where and select functions of python numpy
The Difference Between Where and Select Functions of Python NumPy | Towards Data Science
August 15, 2021 - The conditions and the values are passed to the select function as a list. The first condition is associated with the first value, the second one is with the second value, and so on.
🌐
APXML
apxml.com › courses › essential-numpy-pandas › chapter-7-data-selection-indexing-pandas › conditional-selection
Conditional Selection (Boolean Indexing)
Boolean Series: Applying a condition to a DataFrame column creates a boolean Series (True/False). Filtering: Use this boolean Series inside [] or .loc to filter the DataFrame. Logical Operators: Combine conditions using & (AND), | (OR), and ~ (NOT). Parentheses are Essential: Always wrap individual conditions in parentheses () when using & or |. Example: (condition1) & (condition2). .loc Integration: Boolean arrays work very effectively with .loc for selecting rows and specific columns simultaneously based on conditions.
🌐
LinkedIn
linkedin.com › pulse › difference-between-where-select-functions-python-numpy-rana
The Difference Between Where and Select Functions of Python NumPy
August 16, 2021 - The select function is more flexible because it allows for creating conditional columns with as many distinct values as needed. We only need to specify the condition for each value separately. Thank you for reading. Please let me know if you have any feedback. ... Don’t have the app? Get it in the Microsoft Store. Open the app ... By ...
🌐
Stack Overflow
stackoverflow.com › questions › 45905698 › select-columns-and-lines-with-condition-from-file-using-numpy › 45906010
python - Select columns and lines with condition from file using numpy - Stack Overflow
import numpy as np matrix = np.loadtxt('file.dat') #select columns column_indicies = [0] selected_columns = matrix[:,column_indicies] x=1E14 #select lines for line in matrix: if float(line) > x: #any ideas? selected_matrix = matrix[selected_lines,selected_columns] np.savetxt('new_file.dat', selected_matrix, fmt='%1.4f')