Challenge - 5 Problems
Argmin and Argmax Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2: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)
Attempts:
2 left
💡 Hint
Look for the position of the smallest number in the array.
✗ Incorrect
The smallest number is 1, which is at index 3 in the array.
❓ Predict Output
intermediate2: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)
Attempts:
2 left
💡 Hint
np.argmax returns the index as if the array was flattened.
✗ Incorrect
The largest number is 15, which is at index 5 when the array is flattened.
❓ data_output
advanced2: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)
Attempts:
2 left
💡 Hint
Look for the smallest value in each column.
✗ Incorrect
For each column, the smallest values are at rows 1, 0, and 1 respectively.
❓ data_output
advanced2: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)
Attempts:
2 left
💡 Hint
Find the largest value in each row and note its index.
✗ Incorrect
The largest values in each row are at indices 1, 0, and 1 respectively.
🧠 Conceptual
expert3: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?
Attempts:
2 left
💡 Hint
Think about how np.argmin handles ties.
✗ Incorrect
np.argmin returns the index of the first minimum value it finds, which is at index 1.