/Curriculum/IntermediateStatistics & Reductions

25. Min/Max & Index FunctionsIntermediate

Find values and indices of extrema with min(), max(), argmin(), and argmax().

12 mins

Concept Overview

`np.argmin()` and `np.argmax()` return the index position where minimum or maximum values occur. In Deep Learning, `argmax` identifies predicted class labels.

Hardware Mental Model

`max()` tells you the highest test score in the class. `argmax()` tells you the roll number of the student who scored it.

Key Concepts (1)Click snippet to load in editor

In classification models, output probabilities like `[0.05, 0.85, 0.10]` are passed to `np.argmax()` to output class index 1.

best_idx = probs.argmax(axis=1)

⚠ Common Mistakes & Pitfalls

Avoid these frequent beginner syntax and logic traps
❌ Incorrect:idx = scores.index(max(scores)) # 🐌 Slow Python list method
✓ Correct:idx = scores.argmax() # ⚡ Fast compiled NumPy method

NumPy ndarrays do not have an `.index()` method. Always use `argmax()` or `argmin()`.

Pro Tip: Use `arr.argmax()` for instant O(N) single-pass maximum index search.

📌 Quick Revision

Core takeaway points from this topic
`arr.min()` / `arr.max()`: Returns minimum or maximum value.
`arr.argmin()` / `arr.argmax()`: Returns index of minimum or maximum value.
`np.nanmin()`, `np.nanmax()`, `np.nanargmax()`: Extrema ignoring NaN values.
Editor: 25. Min/Max & Index Functions
Python ● Ready
Initializing Python IDE...
Ctrl+Enter
Execution Result
Click "RUN CODE" to execute and inspect array state

🎯 Try It Yourself: Practice Challenge

Hands-on Mode

Solve the objective below using NumPy vectorized syntax

Objective:Find Index of Maximum Element

Given `arr = np.array([12, 85, 45, 99, 23])`, find the index of the maximum value using `.argmax()` and print it.

Expected Output Target:3
Practice Workspace
Python ● Ready
Initializing Python IDE...
Ctrl+Enter
Execution Result
Click "RUN CODE" to execute and inspect array state