Your expression works if you add parentheses:

>>> y[(1 < x) & (x < 5)]
array(['o', 'o', 'a'], 
      dtype='|S1')
Answer from jfs on Stack Overflow
🌐
thisPointer
thispointer.com › home › numpy › numpy – select elements by condition
NumPy - Select Elements By Condition - thisPointer
April 29, 2023 - import numpy as np def main(): print('Select elements from Numpy Array based on conditions') #Create an Numpy Array containing elements from 5 to 30 but at equal interval of 2 arr = np.arange(5, 30, 2) print('Contents of the Numpy Array : ' , arr) # Comparision OPerator will be applied to all elements in array boolArr = arr < 10 print('Contents of the Bool Numpy Array : ', boolArr) # Select elements with True at corresponding value in bool array newArr = arr[boolArr] print('Contents of the New Numpy Array : ', newArr) newArr = arr[arr < 10] print('Contents of the New Numpy Array : ', newArr) p
🌐
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 - If the Boolean value at the index (i,j) is True, the element will be selected, otherwise not. For example, this is how you can use NumPy’s broadcasting feature to conditionally select elements that fall in a certain range:
🌐
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 select rows from an array based on a condition using boolean indexing. Check out the following example - Selecting specific columns in a NumPy array is similar to selecting rows.
Find elsewhere
🌐
Codegive
codegive.com › blog › numpy_select_elements_by_condition.php
Numpy select elements by condition
At its heart, numpy select elements by condition refers to the process of extracting or manipulating specific values within a NumPy array based on a logical test. This is primarily achieved through a technique called boolean indexing (also known as boolean masking).
🌐
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])
🌐
Spark By {Examples}
sparkbyexamples.com › home › python › numpy where() multiple conditions
NumPy where() Multiple Conditions - Spark By {Examples}
March 27, 2024 - To select the NumPy array elements from the existing array based on multiple conditions use the & operator along with the where() function. You can specify multiple conditions inside the where() function by enclosing each condition inside a ...
🌐
NumPy
numpy.org › doc › 1.18 › reference › generated › numpy.select.html
numpy.select — NumPy v1.18 Manual
Return elements from one of two arrays depending on condition. ... >>> x = np.arange(10) >>> condlist = [x<3, x>5] >>> choicelist = [x, x**2] >>> np.select(condlist, choicelist) array([ 0, 1, 2, ..., 49, 64, 81])
🌐
Note.nkmk.me
note.nkmk.me › home › python › numpy
NumPy: Extract or delete elements, rows, and columns that satisfy the conditions | note.nkmk.me
May 31, 2019 - It is possible to calculate the sum, average, maximum value, minimum value, standard deviation, etc., of elements that satisfy the condition.
🌐
NumPy
numpy.org › doc › 1.21 › reference › generated › numpy.select.html
numpy.select — NumPy v1.21 Manual
numpy.select(condlist, choicelist, default=0)[source]¶ · Return an array drawn from elements in choicelist, depending on conditions.
🌐
DigitalOcean
digitalocean.com › community › tutorials › python-numpy-where
How to use Python numpy.where() Method | DigitalOcean
Leverage NumPy’s where() function to efficiently select elements from arrays based on conditions, creating new arrays with tailored values.
🌐
w3resource
w3resource.com › python-exercises › numpy › python-numpy-exercise-92.php
NumPy: Select indices satisfying multiple conditions in a NumPy array - w3resource
August 29, 2025 - b[(100 < a) & (a < 110)]: Use boolean indexing to select elements from array 'b' where the corresponding elements in array 'a' satisfy the condition (greater than 100 and less than 110).