What’s actually slowing this PC down?
Pick the symptom - the matching free tool is one click away.
For a regular Python list, use max() with enumerate() to get the maximum value and its zero-based index in one pass. For a NumPy array, use np.argmax() for the index and retrieve the value at that position.
Find the maximum value and index in a Python list
enumerate() pairs each value with its index, and max() can compare those pairs by the value. Because enumerate() starts at zero by default, the returned index is zero-based.
values = [4, 12, 7, 12, 3]
index, value = max(enumerate(values), key=lambda pair: pair[1])
print(value) # 12
print(index) # 1
The key function tells max() to compare each pair using its second item, the value. If the maximum occurs more than once, Python returns the first maximal item encountered, so this example gives index 1, not 3. See the Python 3.13 built-in functions reference.
Choose another approach when it fits better
Get the value first, then find its first index
For a short, reusable list, two straightforward calls can be easy to read:
Do these 3 things before closing this tab:
1Fix the driver behind crashes, sound loss and screen glitches2Clear out junk files and repair common Windows errors3Scan for outdated or missing drivers - takes under a minute#1 Best Overall
value = max(values)
index = values.index(value)
list.index() returns the first matching position. This method scans for the maximum and then searches again for its first occurrence; use the enumerate() approach when you want both results in one pass.
Use an explicit loop for custom handling
A loop is useful when you want to make validation or tie behavior explicit. Check that the list is nonempty, initialize the best value and index from its first element, then update them only when a strictly larger value appears. Using a strict comparison preserves the first occurrence on ties.
Rank #2
if not values:
raise ValueError("values must not be empty")
best_index = 0
best_value = values[0]
for index, value in enumerate(values[1:], start=1):
if value > best_value:
best_index = index
best_value = value
Starting the comparison from the first element also handles lists whose values are all negative; initializing the best value to 0 would give an incorrect result for such a list.
Find the maximum in a NumPy array
One-dimensional array
For a one-dimensional NumPy array, np.argmax() returns the index of the maximum. Use that index to retrieve the value:
Windows Errors? Fix Them Before They Spread
Repair common Windows errors and clear accumulated junk for a smoother, more stable PC - no reinstall needed.Free scan · no reinstallCrashes, 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 minuteimport numpy as np
array = np.array([4, 12, 7, 12, 3])
index = np.argmax(array)
value = array[index]
NumPy documents that argmax() returns the index into the flattened array by default. When the maximum is tied, it returns the first occurrence. See the NumPy 2.0 argmax reference.
Multidimensional array
For a multidimensional array, decide whether you need an index along a particular axis or the coordinates of one overall maximum.
- Along an axis: pass
axis=tonp.argmax()to get indices along that axis. - Coordinates of the overall maximum: convert the flattened index into coordinates with
np.unravel_index().
flat_index = np.argmax(array)
coordinates = np.unravel_index(flat_index, array.shape)
value = array[coordinates]
The resulting coordinate tuple can index the original array. See the NumPy 2.0 unravel_index reference.
Handle empty input and NaNs deliberately
Empty Python list
Calling max() on an empty iterable without a default raises ValueError. For the index-and-value recipe, checking first is clearer than relying on a default, because a default supplies one value rather than an index-value pair.
Recommended Free Tools
Best Value
if values:
index, value = max(enumerate(values), key=lambda pair: pair[1])
else:
index = value = None # Choose a sentinel that suits your application
None is only one possible application convention; callers may instead raise an error or handle the empty case another way. Python documents the empty-iterable behavior and the default argument in its built-in functions reference.
NaN values in NumPy
NumPy’s max() propagates NaNs, while nanmax() ignores them. Do not assume that argmax() ignores NaNs or that the value and index functions have matching NaN behavior. If you need a NaN-aware index, consult the nanargmax() documentation for your installed NumPy version and decide how your code should handle all-NaN or empty slices. The NumPy 2.0 max reference documents its NaN behavior.
Quick Recap
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.




