0
0
NumPydata~20 mins

np.argmin() and np.argmax() in NumPy - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Argmin and Argmax Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
Find the index of the smallest element in a 1D array
What is the output of the following code?
NumPy
import numpy as np
arr = np.array([4, 2, 9, 1, 7])
result = np.argmin(arr)
print(result)
A3
B0
C1
D4
Attempts:
2 left
💡 Hint
Look for the position of the smallest number in the array.
Predict Output
intermediate
2:00remaining
Find the index of the largest element in a 2D array flattened
What is the output of this code?
NumPy
import numpy as np
arr = np.array([[5, 12, 7], [3, 9, 15]])
result = np.argmax(arr)
print(result)
A2
B4
C5
D3
Attempts:
2 left
💡 Hint
np.argmax returns the index as if the array was flattened.
data_output
advanced
2:30remaining
Find indices of minimum values along axis 0
Given the array below, what is the output of np.argmin(arr, axis=0)?
NumPy
import numpy as np
arr = np.array([[8, 3, 5], [2, 7, 1], [6, 4, 9]])
result = np.argmin(arr, axis=0)
print(result)
A[2 0 2]
B[1 0 1]
C[0 1 0]
D[1 2 1]
Attempts:
2 left
💡 Hint
Look for the smallest value in each column.
data_output
advanced
2:30remaining
Find indices of maximum values along axis 1
What does np.argmax(arr, axis=1) return for the array below?
NumPy
import numpy as np
arr = np.array([[1, 4, 2], [9, 3, 5], [7, 8, 6]])
result = np.argmax(arr, axis=1)
print(result)
A[1 0 1]
B[2 1 0]
C[0 2 1]
D[1 2 2]
Attempts:
2 left
💡 Hint
Find the largest value in each row and note its index.
🧠 Conceptual
expert
3:00remaining
Understanding behavior of np.argmin with multiple minimum values
Consider the array arr = np.array([3, 1, 2, 1, 4]). What index does np.argmin(arr) return and why?
A3, because np.argmin returns the last occurrence of the minimum value
BRaises an error because there are multiple minimum values
C2, because np.argmin returns the index of the second smallest value
D1, because np.argmin returns the first occurrence of the minimum value
Attempts:
2 left
💡 Hint
Think about how np.argmin handles ties.