Loading Page Content...
Preparing courses, live labs, and learning resources.सामग्री लोड हो रही है, कृपया प्रतीक्षा करें...
Preparing courses, live labs, and learning resources.सामग्री लोड हो रही है, कृपया प्रतीक्षा करें...
Finding where extreme values occur—such as locating the maximum probability class in neural network classification, pinpointing the peak signal in a spectroscopy scan, or identifying active sensor triggers—is a standard task across numerical science.
NumPy provides fast vector routines for searching arrays:
np.argmax() / np.argmin(): Indices of global or directional extrema.np.unravel_index(): Converting flat 1D indices into multi-dimensional coordinates.np.nonzero(): Finding coordinates of non-zero elements.argmax() and argmin() return the index of the first occurrence.axis ParameterIn classification machine learning (such as MNIST digit recognition or image tagging), the model outputs a 2D matrix of shape (batch_size, num_classes) containing predicted probability scores. To extract the predicted class for each sample, compute argmax across class columns (axis=1):
np.unravel_index()When argmax() is called on a multi-dimensional array without specifying an axis, it flattens the array conceptually and returns a single integer representing the flat index.
To convert that flat integer into true $(row, col)$ or $(depth, row, col)$ coordinates, use np.unravel_index():
np.nonzero()np.nonzero() returns a tuple of coordinate arrays, one for each dimension, containing the indices where elements are non-zero:
np.argmax() return?probs of shape (100, 10) (100 samples, 10 classes), which command extracts the predicted class for each sample?np.count_nonzero(arr) do?arr = np.array([[0, 8], [3, 0]]), what is returned by np.nonzero(arr)?Continue learning with hands-on practice, examples, and exercises in the upcoming topic.
Test your understanding of this lesson with 5 questions. Each question has one correct answer.