Challenge - 5 Problems
np.min() and np.max() Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
Output of np.min() on a 2D array with axis parameter
What is the output of the following code?
import numpy as np arr = np.array([[3, 7, 5], [1, 6, 9]]) result = np.min(arr, axis=0) print(result)
NumPy
import numpy as np arr = np.array([[3, 7, 5], [1, 6, 9]]) result = np.min(arr, axis=0) print(result)
Attempts:
2 left
💡 Hint
Think about what axis=0 means for a 2D array.
✗ Incorrect
np.min with axis=0 finds the minimum value in each column. For columns: [3,1], [7,6], [5,9], the minimums are 1, 6, and 5 respectively.
❓ data_output
intermediate2:00remaining
Number of elements in np.max() result with keepdims=True
Given the code below, how many elements are in the resulting array?
import numpy as np arr = np.array([[4, 2, 8], [7, 1, 5]]) result = np.max(arr, axis=1, keepdims=True) print(result) print(result.size)
NumPy
import numpy as np arr = np.array([[4, 2, 8], [7, 1, 5]]) result = np.max(arr, axis=1, keepdims=True) print(result) print(result.size)
Attempts:
2 left
💡 Hint
Keepdims keeps the dimension, but does not change the number of rows.
✗ Incorrect
np.max with axis=1 and keepdims=True returns a 2x1 array. So total elements = 2.
🔧 Debug
advanced2:00remaining
Identify the error in np.min() usage
What error does the following code raise?
import numpy as np arr = np.array([1, 2, 3]) result = np.min(arr, axis=1) print(result)
NumPy
import numpy as np arr = np.array([1, 2, 3]) result = np.min(arr, axis=1) print(result)
Attempts:
2 left
💡 Hint
Check the shape of the array and the axis parameter.
✗ Incorrect
The array is 1D, so axis=1 is invalid and raises AxisError.
🚀 Application
advanced2:00remaining
Find the maximum value ignoring NaNs
Which code correctly finds the maximum value in the array ignoring NaN values?
import numpy as np arr = np.array([3, np.nan, 7, 2])
NumPy
import numpy as np arr = np.array([3, np.nan, 7, 2])
Attempts:
2 left
💡 Hint
Look for a numpy function that ignores NaNs automatically.
✗ Incorrect
np.nanmax returns the max ignoring NaNs. np.max returns NaN if any NaN present. Option D works but is less direct. Option D is invalid syntax.
🧠 Conceptual
expert3:00remaining
Effect of np.min() and np.max() on empty arrays
What happens when you call np.min() or np.max() on an empty numpy array?
import numpy as np empty_arr = np.array([]) min_val = np.min(empty_arr) max_val = np.max(empty_arr)
NumPy
import numpy as np empty_arr = np.array([]) min_val = np.min(empty_arr) max_val = np.max(empty_arr)
Attempts:
2 left
💡 Hint
Think about what minimum or maximum means for no elements.
✗ Incorrect
Calling np.min or np.max on an empty array raises ValueError because there is no identity value to return.