What do np.argmin and np.argmax return, and how do they differ from np.min and np.max?

Quick Overview

A NumPy interview question asking what np.argmin and np.argmax return and how they differ from np.min and np.max. It tests positions versus values, tie handling, the axis argument and flat indices on multi-dimensional arrays, and how NaN and empty arrays behave.

What do np.argmin and np.argmax return, and how do they differ from np.min and np.max?

Role: Data Scientist

Category: Data Manipulation (SQL/Python)

Difficulty: easy

Interview Round: Other

What do `np.argmin` and `np.argmax` return, and how do they differ from `np.min` and `np.max`? ```hint Try small arrays Picture each function on a 1-D array with a repeated maximum, then on a 2-D array with and without an `axis` argument, and compare what comes back. ``` ### What a Strong Answer Covers - What each pair returns (a position or a value) and when you need one or the other - How ties are resolved - What the result means for a multi-dimensional array with and without an `axis` argument, and how to turn a flat index into coordinates - How NaN values and empty arrays are handled ### Follow-up Questions - How would you get the indices of the three largest values without sorting the whole array? - Given a 2-D array of class probabilities, how do you get each row's predicted class and its probability? - What do `np.argmax` and `np.nanargmax` return for an array that contains NaN? - How would you find the index of the last occurrence of the maximum instead of the first?

Overview: A NumPy interview question asking what np.argmin and np.argmax return and how they differ from np.min and np.max. It tests positions versus values, tie handling, the axis argument and flat indices on multi-dimensional arrays, and how NaN and empty arrays behave.

General logo
General
Nov 25, 2026
easyData ScientistOtherData Manipulation (SQL/Python)
0
0

What do np.argmin and np.argmax return, and how do they differ from np.min and np.max?

What a Strong Answer Covers Guidance

  • What each pair returns (a position or a value) and when you need one or the other
  • How ties are resolved
  • What the result means for a multi-dimensional array with and without an axis argument, and how to turn a flat index into coordinates
  • How NaN values and empty arrays are handled

Follow-up Questions Guidance

  • How would you get the indices of the three largest values without sorting the whole array?
  • Given a 2-D array of class probabilities, how do you get each row's predicted class and its probability?
  • What do np.argmax and np.nanargmax return for an array that contains NaN?
  • How would you find the index of the last occurrence of the maximum instead of the first?