Bird
0
0

What will be the output of the following code?

medium📝 Predict Output Q5 of 15
NumPy - Aggregation Functions
What will be the output of the following code?
arr = np.array([[2, 4, 6], [1, 3, 5]])
np.min(arr, axis=1)
A[1 2 3]
B[2 1]
C[2 4 6]
D[1 3 5]
Step-by-Step Solution
Solution:
  1. Step 1: Understand the array and axis

    Array shape is (2, 3). Axis=1 means find min across columns for each row.
  2. Step 2: Calculate min along axis=1

    Row 1 min: min(2,4,6) = 2
    Row 2 min: min(1,3,5) = 1
  3. Final Answer:

    [2 1] is the minimum per row -> Option B
  4. Quick Check:

    axis=1 min = row-wise min = [2 1] [OK]
Quick Trick: axis=1 aggregates across columns (row-wise) [OK]
Common Mistakes:
  • Mixing up axis=0 and axis=1
  • Expecting a 2D output
  • Confusing min with max

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More NumPy Quizzes