Use np.where to get the indices where a given condition is True.

Examples:

For a 2D np.ndarray called a:

Use with AIi, j = np.where(a == value) # when comparing arrays of integers

i, j = np.where(np.isclose(a, value)) # when comparing floating-point arrays

For a 1D array:

Use with AIi, = np.where(a == value) # integers

i, = np.where(np.isclose(a, value)) # floating-point

Note that this also works for conditions like >=, <=, != and so forth...

You can also create a subclass of np.ndarray with an index() method:

Use with AIclass myarray(np.ndarray):
    def __new__(cls, *args, **kwargs):
        return np.array(*args, **kwargs).view(myarray)
    def index(self, value):
        return np.where(self == value)

Testing:

Use with AIa = myarray([1,2,3,4,4,4,5,6,4,4,4])
a.index(4)
#(array([ 3,  4,  5,  8,  9, 10]),)
Answer from Saullo G. P. Castro on Stack Overflow
๐ŸŒ
NumPy
numpy.org โ€บ doc โ€บ stable โ€บ user โ€บ basics.indexing.html
Indexing on ndarrays โ€” NumPy v2.5 Manual
As in Python, all indices are zero-based: for the i-th index \(n_i\), the valid range is \(0 \le n_i < d_i\) where \(d_i\) is the i-th element of the shape of the array. Negative indices are interpreted as counting from the end of the array (i.e., if \(n_i < 0\), it means \(n_i + d_i\)). All arrays generated by basic slicing are always views of the original array. ... NumPy slicing creates a view instead of a copy as in the case of built-in Python sequences such as string, tuple and list.
๐ŸŒ
W3Schools
w3schools.com โ€บ python โ€บ numpy โ€บ numpy_array_indexing.asp
NumPy Array Indexing
You can access an array element by referring to its index number. The indexes in NumPy arrays start with 0, meaning that the first element has index 0, and the second has index 1 etc.
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ python โ€บ numpy-indexing
Numpy Array Indexing - GeeksforGeeks
September 22, 2026 - NumPy supports indexing for one-dimensional and multidimensional arrays, along with slicing, Boolean indexing, fancy indexing, and tools such as np.newaxis and ellipsis (...).
๐ŸŒ
Programiz
programiz.com โ€บ python-programming โ€บ numpy โ€บ array-indexing
Numpy Array Indexing (With Examples)
June 1, 2023 - Note: Since the last element of ... index 5 is out of bounds for axis 0 with size 5 ยท We can use indices to change the value of an element in a NumPy array....
๐ŸŒ
NumPy
numpy.org โ€บ devdocs โ€บ user โ€บ basics.indexing.html
Indexing on ndarrays โ€” NumPy v2.6.dev0 Manual
As in Python, all indices are zero-based: for the i-th index \(n_i\), the valid range is \(0 \le n_i < d_i\) where \(d_i\) is the i-th element of the shape of the array. Negative indices are interpreted as counting from the end of the array (i.e., if \(n_i < 0\), it means \(n_i + d_i\)). All arrays generated by basic slicing are always views of the original array. ... NumPy slicing creates a view instead of a copy as in the case of built-in Python sequences such as string, tuple and list.
๐ŸŒ
Python Like You Mean It
pythonlikeyoumeanit.com โ€บ Module3_IntroducingNumpy โ€บ BasicIndexing.html
Introducing Basic and Advanced Indexing โ€” Python Like You Mean It
Thus far we have seen that we can access the contents of a NumPy array by specifying an integer or slice-object as an index for each one of its dimensions. Indexing into and slicing along the dimensions of an array are known as basic indexing.
๐ŸŒ
DataCamp
datacamp.com โ€บ doc โ€บ numpy โ€บ array-indexing
NumPy Array Indexing
NumPy array indexing is used to extract or modify elements in an array based on their indices.
Find elsewhere
๐ŸŒ
NumPy
numpy.org โ€บ devdocs โ€บ user โ€บ how-to-index.html
How to index ndarrays โ€” NumPy v2.6.dev0 Manual
To index specific elements in each column, make use of Advanced indexing as below: >>> arr = np.arange(3*4).reshape(3, 4) >>> arr array([[ 0, 1, 2, 3], [ 4, 5, 6, 7], [ 8, 9, 10, 11]]) >>> column_indices = [[1, 3], [0, 2], [2, 2]] >>> np.arange(arr.shape[0]) array([0, 1, 2]) >>> row_indices = np.arange(arr.shape[0])[:, np.newaxis] >>> row_indices array([[0], [1], [2]])
๐ŸŒ
Medium
medium.com โ€บ @whyamit404 โ€บ basics-of-numpy-array-indexing-9052e6d6b5cf
Basics of NumPy Array Indexing. If you think you need to spend $2,000โ€ฆ | by whyamit404 | Medium
February 9, 2025 - Whether you want a specific range or skip every other slice, NumPy makes it easy. Letโ€™s dive into the details! Slicing allows you to grab a portion of your array using the syntax: start:stop:step Hereโ€™s how it works: Start: The index where your slice begins (inclusive).
๐ŸŒ
NumPy
numpy.org โ€บ doc โ€บ 1.21 โ€บ reference โ€บ arrays.indexing.html
Indexing โ€” NumPy v1.21 Manual
June 22, 2021 - As in Python, all indices are zero-based: for the i-th index \(n_i\), the valid range is \(0 \le n_i < d_i\) where \(d_i\) is the i-th element of the shape of the array. Negative indices are interpreted as counting from the end of the array (i.e., if \(n_i < 0\), it means \(n_i + d_i\)). All arrays generated by basic slicing are always views of the original array. ... NumPy slicing creates a view instead of a copy as in the case of builtin Python sequences such as string, tuple and list.
๐ŸŒ
SciPy
docs.scipy.org โ€บ doc โ€บ โ€บ numpy-1.11.0 โ€บ user โ€บ basics.indexing.html
Indexing โ€” NumPy v1.11 Manual
May 29, 2016 - Single element indexing for a 1-D ... indices for indexing from the end of the array. ... Unlike lists and tuples, numpy arrays support multidimensional indexing for multidimensional arrays....
๐ŸŒ
NumPy
numpy.org โ€บ doc โ€บ 1.16 โ€บ reference โ€บ arrays.indexing.html
Indexing โ€” NumPy v1.16 Manual
February 18, 2020 - For example, x[1:10:5,::-1] can also be implemented as obj = (slice(1,10,5), slice(None,None,-1)); x[obj] . This can be useful for constructing generic code that works on arrays of arbitrary dimension. ... The newaxis object can be used in all slicing operations to create an axis of length one. newaxis is an alias for โ€˜Noneโ€™, and โ€˜Noneโ€™ can be used in place of this with the same result. Advanced indexing is triggered when the selection object, obj, is a non-tuple sequence object, an ndarray (of data type integer or bool), or a tuple with at least one sequence object or ndarray (of data type integer or bool).
๐ŸŒ
NumPy
numpy.org โ€บ doc โ€บ 1.20 โ€บ reference โ€บ arrays.indexing.html
Indexing โ€” NumPy v1.20 Manual
January 31, 2021 - As in Python, all indices are zero-based: for the i-th index , the valid range is where is the i-th element of the shape of the array. Negative indices are interpreted as counting from the end of the array (i.e., if , it means ). All arrays generated by basic slicing are always views of the original array. ... NumPy slicing creates a view instead of a copy as in the case of builtin Python sequences such as string, tuple and list.
๐ŸŒ
Problem Solving with Python
problemsolvingwithpython.com โ€บ 05-NumPy-and-Arrays โ€บ 05.05-Array-Indexing
Array Indexing - Problem Solving with Python
Elements in NumPy arrays can be accessed by indexing. Indexing is an operation that pulls out a select set of values from an array. The index of a value in an array is that value's location within the array.
๐ŸŒ
Pluralsight
pluralsight.com โ€บ blog โ€บ tech guides & tutorials
Working with Numpy Arrays: Indexing & Slicing | Pluralsight
To access elements in this array, use two indices. One for the row and the other for the column. Note that both the column and the row indices start with 0. So if I need to access the value โ€˜10,โ€™ use the index โ€˜3โ€™ for the row and index โ€˜1โ€™ for the column.
๐ŸŒ
NumPy
numpy.org โ€บ doc โ€บ 1.26 โ€บ reference โ€บ arrays.indexing.html
Indexing routines โ€” NumPy v1.26 Manual
Indexing on ndarrays ยท Translates slice objects to concatenation along the second axis
๐ŸŒ
NumPy
numpy.org โ€บ doc โ€บ 2.2 โ€บ user โ€บ basics.indexing.html
Indexing on ndarrays โ€” NumPy v2.2 Manual
As in Python, all indices are zero-based: for the i-th index \(n_i\), the valid range is \(0 \le n_i < d_i\) where \(d_i\) is the i-th element of the shape of the array. Negative indices are interpreted as counting from the end of the array (i.e., if \(n_i < 0\), it means \(n_i + d_i\)). All arrays generated by basic slicing are always views of the original array. ... NumPy slicing creates a view instead of a copy as in the case of built-in Python sequences such as string, tuple and list.
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ python โ€บ numpy-slicing-and-indexing
Basic Slicing and Advanced Indexing in NumPy - GeeksforGeeks
Indexing with index arrays lets you fetch multiple elements from a NumPy array at once using their index positions.
Published: November 4, 2025
๐ŸŒ
Readthedocs
scipy-cookbook.readthedocs.io โ€บ items โ€บ Indexing.html
Indexing numpy arrays โ€” SciPy Cookbook documentation
June 1, 2008 - In its simplest (and most common) incarnation, you simply supply a single boolean array as index, the same shape as the original array: ... You then get back a one-dimensional array of the elements for which the condition is True. (Note that the array must be one-dimensional, since the boolean ...