Crashes, No Sound, or Screen Glitches?
Random freezes, missing sound and display glitches usually trace back to one bad driver. Find and replace yours safely.Free scan · under a minutePC Slower Than It Used to Be?
A free scan shows the junk files, broken settings and background clutter dragging Windows down - then fixes them in one click.Free scan · Windows 10 & 11For a regular Python list, use items.index(value) to get the zero-based position of its first match. For a NumPy array, compare the array with the value and use np.where() to find matching positions. The right method depends on whether “array” means a list or a NumPy ndarray, and whether you need one match or all of them.
Find an element’s index in a Python list
Call the list’s index() method:
items = ["red", "blue", "green"]
position = items.index("blue")
print(position) # 1
Python list positions start at zero, so the first item is at index 0. The method returns the first occurrence of the value. If the value is not in the list, it raises ValueError. See the Python 3.14.8 tutorial for the documented behavior.
Search within part of a list
list.index(value[, start[, stop]]) accepts optional start and stop bounds. The search is limited to that portion, but the returned index remains relative to the whole list:
items = ["red", "blue", "green", "blue"]
position = items.index("blue", 2) # 3
Find the first match, all matches, or handle no match
Because index() returns only the first match, use a list comprehension with enumerate() when you need every matching position:
Free tools Windows power users keep installed
One-click scans. No signup required.
#1 Best Overall
items = ["red", "blue", "green", "blue"]
target = "blue"
positions = [i for i, value in enumerate(items) if value == target]
print(positions) # [1, 3]
If nothing matches, this produces an empty list. By contrast, items.index(target) raises ValueError. Use index() when absence should be treated as an error; collect positions when zero, one, or many matches are all expected outcomes.
Find matching positions in a NumPy array
NumPy arrays do not use the list’s .index() method. Compare the array with the target; np.where() returns the positions where the comparison is true. For a one-dimensional array, select the first index array from its result:
Rank #2
import numpy as np
arr = np.array([10, 20, 30, 20])
positions = np.where(arr == 20)[0]
print(positions) # [1 3]
This finds all matches. An empty result means no element matched. NumPy uses zero-based indexing; its where documentation describes the function’s behavior.
Represent matches in a multidimensional NumPy array
For a two-dimensional array, each match has a row and a column coordinate. Choose the result format based on what you will do with those coordinates:
arr = np.array([[4, 7], [7, 9]])
coordinates = np.argwhere(arr == 7) # [[0, 1], [1, 0]]
index_arrays = np.nonzero(arr == 7) # (array([0, 1]), array([1, 0]))
np.argwhere(condition)presents matches as coordinate rows. For this example, the matches are at row 0, column 1 and row 1, column 0. Its output has shape(number_of_matches, number_of_dimensions). NumPy cautions that this output is not suitable for indexing an array; see the argwhere documentation.np.nonzero(condition)returns one integer index array per dimension. Use it when you want index arrays for indexing the original array. NumPy documents this per-dimension indexing in its indexing guide.
Keep the per-axis coordinates when row and column matter. A flattened index is useful only when the application specifically needs a single position in a flattened one-dimensional sequence.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Which “Python array” do you have?
The phrase can mean a regular list, a NumPy ndarray, or Python’s separate standard-library array type. These are distinct data structures, so identify the type before choosing a lookup method. The built-in list method is documented in the Python tutorial; the standard-library type is described in the array module documentation; NumPy’s array indexing behavior is covered in its indexing guide.
Quick Recap
Best Value
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.




