Bird
0
0

Why does np.min() return a scalar when applied to a 1D array but an array when used with axis parameter on a 2D array?

hard📝 Conceptual Q10 of 15
NumPy - Aggregation Functions
Why does np.min() return a scalar when applied to a 1D array but an array when used with axis parameter on a 2D array?
ABecause np.min() cannot handle 2D arrays without axis
BBecause np.min() always returns arrays regardless of input
CBecause 1D arrays have no axis parameter
DBecause axis specifies dimension to reduce, returning array of mins per slice
Step-by-Step Solution
Solution:
  1. Step 1: Understand np.min() behavior on 1D arrays

    On 1D arrays, np.min() returns a single smallest value (scalar).
  2. Step 2: Understand axis parameter effect on 2D arrays

    When axis is given, np.min() reduces along that axis, returning an array of minimums per row or column.
  3. Final Answer:

    Because axis specifies dimension to reduce, returning array of mins per slice -> Option D
  4. Quick Check:

    axis controls output shape of np.min() [OK]
Quick Trick: axis parameter controls output shape of np.min() [OK]
Common Mistakes:
  • Thinking np.min() always returns scalar
  • Ignoring axis effect
  • Believing 1D arrays lack axis

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More NumPy Quizzes