Bird
0
0

What is the output of the following code?

medium📝 Predict Output Q4 of 15
NumPy - Aggregation Functions
What is the output of the following code?
import numpy as np
arr = np.array([10, 20, 5, 30])
print(np.argmax(arr))
A1
B3
C2
D0
Step-by-Step Solution
Solution:
  1. Step 1: Identify the maximum value in the array

    The array is [10, 20, 5, 30]. The largest value is 30.
  2. Step 2: Find the index of the maximum value

    30 is at index 3.
  3. Final Answer:

    3 -> Option B
  4. Quick Check:

    np.argmax(arr) = 3 [OK]
Quick Trick: np.argmax() returns index of max value in array [OK]
Common Mistakes:
  • Returning the max value instead of index
  • Confusing index positions
  • Using argmin instead of argmax

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More NumPy Quizzes