After fiddling around for a while, I figured things out, and am posting them here hoping it will help others.

Intuitively, np.where is like asking "tell me where in this array, entries satisfy a given condition".

>>> a = np.arange(5,10)
>>> np.where(a < 8)       # tell me where in a, entries are < 8
(array([0, 1, 2]),)       # answer: entries indexed by 0, 1, 2

It can also be used to get entries in array that satisfy the condition:

>>> a[np.where(a < 8)] 
array([5, 6, 7])          # selects from a entries 0, 1, 2

When a is a 2d array, np.where() returns an array of row idx's, and an array of col idx's:

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

As in the 1d case, we can use np.where() to get entries in the 2d array that satisfy the condition:

>>> a[np.where(a > 8)] # selects from a entries 0, 1, 2

array([9])


Note, when a is 1d, np.where() still returns an array of row idx's and an array of col idx's, but columns are of length 1, so latter is empty array.

Answer from Alex Dalyac on Stack Overflow
🌐
NumPy
numpy.org › doc › stable › reference › generated › numpy.where.html
numpy.where — NumPy v2.5 Manual
If all the arrays are 1-D, where is equivalent to: [xv if c else yv for c, xv, yv in zip(condition, x, y)] Examples · Try it in your browser! >>> import numpy as np >>> a = np.arange(10) >>> a array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9]) >>> np.where(a < 5, a, 10*a) array([ 0, 1, 2, 3, 4, 50, 60, 70, 80, 90]) This can be used on multidimensional arrays too: >>> np.where([[True, False], [True, True]], ...
🌐
NumPy
numpy.org › devdocs › reference › generated › numpy.where.html
numpy.where — NumPy v2.6.dev0 Manual
If all the arrays are 1-D, where is equivalent to: [xv if c else yv for c, xv, yv in zip(condition, x, y)] Examples · Try it in your browser! >>> import numpy as np >>> a = np.arange(10) >>> a array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9]) >>> np.where(a < 5, a, 10*a) array([ 0, 1, 2, 3, 4, 50, 60, 70, 80, 90]) This can be used on multidimensional arrays too: >>> np.where([[True, False], [True, True]], ...
🌐
NumPy
numpy.org › doc › 2.2 › reference › generated › numpy.where.html
numpy.where — NumPy v2.2 Manual
If all the arrays are 1-D, where is equivalent to: [xv if c else yv for c, xv, yv in zip(condition, x, y)] Examples · >>> import numpy as np >>> a = np.arange(10) >>> a array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9]) >>> np.where(a < 5, a, 10*a) array([ 0, 1, 2, 3, 4, 50, 60, 70, 80, 90]) This can be used on multidimensional arrays too: >>> np.where([[True, False], [True, True]], ...
🌐
GeeksforGeeks
geeksforgeeks.org › numpy › numpy-where-in-python
numpy.where() in Python - GeeksforGeeks
September 30, 2025 - Here, numpy.where() function checks the condition arr > 20.
🌐
Machine Learning Plus
machinelearningplus.com › blog › how to use numpy where function?
How to Use Numpy Where Function? - machinelearningplus
January 26, 2023 - When the np.where() function is applied to a 2-D numpy array, a tuple containing two arrays is returned. These arrays correspond to respective indices of an element in both dimensions. An element position is determined by taking one value each from arrays in order. See the example below.
🌐
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.
🌐
NumPy
numpy.org › doc › 2.1 › reference › generated › numpy.where.html
numpy.where — NumPy v2.1 Manual
If all the arrays are 1-D, where is equivalent to: [xv if c else yv for c, xv, yv in zip(condition, x, y)] Examples · >>> import numpy as np >>> a = np.arange(10) >>> a array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9]) >>> np.where(a < 5, a, 10*a) array([ 0, 1, 2, 3, 4, 50, 60, 70, 80, 90]) This can be used on multidimensional arrays too: >>> np.where([[True, False], [True, True]], ...
Find elsewhere
🌐
Cherry Servers
cherryservers.com › home › blog › cloud computing › how to use numpy.where function [with examples]
How to Use numpy.where Function [With Examples]
November 7, 2025 - In the following numpy.where example, when the condition (x > 2) & (x <= 8) evaluates to true, the new array includes the original values in the x array.
🌐
Real Python
realpython.com › numpy-where-conditional-expressions
How to Use Conditional Expressions With NumPy where() – Real Python
July 12, 2026 - You would typically use np.where() when you have an array and need to analyze its elements differently depending on their values. For example, you might need to replace negative numbers with zeros or replace missing values such as None or np.nan ...
🌐
DataCamp
datacamp.com › doc › numpy › where
NumPy where()
import numpy as np x = np.array([1, 2, 3, 4, 5]) y = np.array([10, 20, 30, 40, 50]) result = np.where(x > 3, x, y) print(result) In this example, elements from `x` are selected where `x > 3`, and from `y` otherwise, resulting in `array([10, 20, 30, 4, 5])`.
🌐
Vultr Docs
docs.vultr.com › python › third party › numpy › where()
Python Numpy where() - Conditional Element Search
December 30, 2024 - This snippet extracts the elements from data using the indices found by numpy.where(), displaying the data that meets the condition. Define an array with more complex criteria. Use logical operators like & (and) and | (or) to combine conditions. ... This example searches for values that are greater than 2 and less than 6.
🌐
Squash
squash.io › python-numpy-where-tutorial
Python Numpy.where() Tutorial - Squash Labs
August 1, 2023 - The numpy.where() function takes three parameters: condition, x, and y. The condition parameter is a boolean array that specifies the condition for selecting elements. The x parameter is the value to be selected when the condition is True, and the y parameter is the value to be selected when the condition is False. Here is a basic example that demonstrates the usage of numpy.where():
🌐
Spark By {Examples}
sparkbyexamples.com › home › python › numpy where() function with examples
NumPy where() Function With Examples - Spark By {Examples}
March 27, 2024 - Python NumPy where() function is used to return the indices of elements in an input array where the given condition is satisfied. Use this function to
🌐
NumPy
numpy.org › doc › 2.0 › reference › generated › numpy.where.html
numpy.where — NumPy v2.0 Manual
An array with elements from x where condition is True, and elements from y elsewhere.
🌐
Python Guides
pythonguides.com › python-numpy-where
Optimizing Data Analysis in Pandas Using np.where() in 2025
May 16, 2025 - In this example, I’ve used np.where() to create a new column called ‘Performance’ that labels each state as either ‘High’ or ‘Regular’ based on their sales figures. Check out Replace Values in NumPy Array by Index in Python
🌐
StrataScratch
stratascratch.com › blog › exploring-numpy-where-in-python
Exploring NumPy where() in Python for Conditional Operations - StrataScratch
September 17, 2025 - In this article, we explored numpy.where() through simple examples, multi-dimensional use cases, and real interview-level questions.
🌐
IONOS
ionos.com › digital guide › websites › web development › python np.where method
What is np.where in Python? - IONOS
January 2, 2025 - The np.where() function takes a NumPy-like array that consists of, for example, integers or Boolean values.
🌐
Programiz
programiz.com › python-programming › numpy › methods › where
NumPy where()
The NumPy where() method finds indices that are true in an array based on a given condition. The numpy.where() method returns a new array based on a condition applied to each element of an array.
🌐
Medium
medium.com › @heyamit10 › understanding-numpy-where-with-two-conditions-21871ed01aa6
Understanding numpy.where() with Two Conditions | by Hey Amit | Medium
March 6, 2025 - Think of numpy.where() as a decision-maker for your arrays. It checks a condition, and based on whether it’s True or False, it picks a value for you.