Bird
0
0

What is the output of the following code?

medium📝 Predict Output Q13 of 15
NumPy - Aggregation Functions
What is the output of the following code?
import numpy as np
arr = np.array([[3, 7, 2], [5, 1, 9]])
print(np.min(arr, axis=0))
A[3 1 2]
B[3 7 2]
C[5 1 9]
D[1 2 3]
Step-by-Step Solution
Solution:
  1. Step 1: Understand axis=0 in np.min()

    Using axis=0 means finding the minimum value down each column.
  2. Step 2: Calculate minimum per column

    Column 1: min(3,5) = 3
    Column 2: min(7,1) = 1
    Column 3: min(2,9) = 2
  3. Final Answer:

    [3 1 2] -> Option A
  4. Quick Check:

    np.min(arr, axis=0) = [3 1 2] [OK]
Quick Trick: axis=0 finds min down columns, axis=1 across rows [OK]
Common Mistakes:
  • Mixing axis=0 and axis=1
  • Confusing min with max
  • Expecting a single number instead of array

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More NumPy Quizzes