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 › 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 › 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]], ...
🌐
GeeksforGeeks
geeksforgeeks.org › numpy › numpy-where-in-python
numpy.where() in Python - GeeksforGeeks
September 30, 2025 - In this example, numpy.where() checks where the condition arr % 2 == 0 is true and returns the indices.
🌐
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]], ...
🌐
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) Powered by · In this example, elements from `x` are selected where `x > 3`, and from `y` otherwise, resulting in `array([10, 20, 30, 4, 5])`.
🌐
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]], ...
🌐
IONOS
ionos.com › digital guide › websites › web development › python np.where method
What is np.where in Python? - IONOS
February 1, 2025 - The np.where() function takes a NumPy-like array that consists of, for example, integers or Boolean values.
Find elsewhere
🌐
DigitalOcean
digitalocean.com › community › tutorials › python-numpy-where
How to use Python numpy.where() Method | DigitalOcean
August 3, 2022 - Leverage NumPy’s where() function to efficiently select elements from arrays based on conditions, creating new arrays with tailored values.
🌐
Programiz
programiz.com › python-programming › numpy › methods › where
NumPy where() | Programiz
August 30, 2023 - 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.
🌐
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 ...
🌐
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.
🌐
AskPython
askpython.com › python-modules › numpy › python-numpy-where
np.where in Python: Find Indices and Replace Values with numpy.where() - AskPython
September 29, 2026 - Call np.where with only a condition and it answers with a tuple of index positions, not the values themselves. That shape catches you on the first line you
🌐
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.
🌐
Python Guides
pythonguides.com › python-numpy-where
Optimizing Data Analysis in Pandas Using np.where() in 2025
May 8, 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
🌐
NumPy
numpy.org › doc › 2.4 › reference › generated › numpy.where.html
numpy.where — NumPy v2.4 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]], ...
🌐
OpenSourceOptions
opensourceoptions.com › how-to-use-numpy-where-in-python-with-examples
How to Use numpy.where() in Python with Examples – OpenSourceOptions
The general usage of numpy.where is as follows: numpy.where(condition, value if true (optional), value if false (optional) ). The condition is applied to a numpy array and must evaluate to a boolean. For example a > 5 where a is a numpy 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.
🌐
NumPy
numpy.org › doc › 2.3 › reference › generated › numpy.where.html
numpy.where — NumPy v2.3 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]], ...