Bird
Raised Fist0
NumPydata~20 mins

np.min() and np.max() in NumPy - Practice Problems & Coding Challenges

Choose your learning style10 modes available
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
intermediate
2: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)
A[1 6 5]
B[1 7 5]
C[3 7 5]
D[1 6 9]
Attempts:
2 left
💡 Hint
Think about what axis=0 means for a 2D array.
❓ data_output
intermediate
2: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)
A3
B6
C2
D1
Attempts:
2 left
💡 Hint
Keepdims keeps the dimension, but does not change the number of rows.
🔧 Debug
advanced
2: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)
ATypeError: 'int' object is not iterable
BAxisError: axis 1 is out of bounds for array of dimension 1
CValueError: operands could not be broadcast together
DNo error, output is 1
Attempts:
2 left
💡 Hint
Check the shape of the array and the axis parameter.
🚀 Application
advanced
2: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])
Anp.max(arr, where=~np.isnan(arr))
Bnp.max(arr)
Cnp.max(arr[~np.isnan(arr)])
Dnp.nanmax(arr)
Attempts:
2 left
💡 Hint
Look for a numpy function that ignores NaNs automatically.
🧠 Conceptual
expert
3: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)
ABoth calls raise a ValueError: zero-size array to reduction operation minimum/maximum which has no identity
Bmin_val is 0, max_val is 0
CBoth min_val and max_val are np.inf and -np.inf respectively
Dmin_val and max_val are None
Attempts:
2 left
💡 Hint
Think about what minimum or maximum means for no elements.

Practice

(1/5)
1. What does the function np.min() do when applied to a NumPy array?
easy
A. Calculates the average of the array
B. Finds the largest value in the array
C. Finds the smallest value in the array
D. Counts the number of elements in the array

Solution

  1. Step 1: Understand the purpose of np.min()

    The function np.min() is designed to find the minimum value in a NumPy array.
  2. Step 2: Compare with other options

    Options B, C, and D describe different functions: max, mean, and size respectively, which are not what np.min() does.
  3. Final Answer:

    Finds the smallest value in the array -> Option C
  4. Quick Check:

    np.min() = smallest value [OK]
Hint: np.min() always returns the smallest number [OK]
Common Mistakes:
  • Confusing np.min() with np.max()
  • Thinking np.min() calculates average
  • Assuming np.min() counts elements
2. Which of the following is the correct NumPy function syntax to find the maximum value in a NumPy array named arr?
easy
A. max(arr)
B. np.max(arr)
C. np.maximum(arr)
D. arr.max()

Solution

  1. Step 1: Identify correct function usage

    The function np.max(arr) correctly finds the maximum value in the array arr.
  2. Step 2: Analyze other options

    arr.max() is valid but uses method syntax, not function syntax. np.maximum(arr) is incorrect because np.maximum() compares two arrays element-wise. max(arr) is Python's built-in max, which works on lists but not efficiently on NumPy arrays.
  3. Final Answer:

    np.max(arr) -> Option B
  4. Quick Check:

    np.max(arr) = max value [OK]
Hint: Use np.max(array) to get max value quickly [OK]
Common Mistakes:
  • Using np.maximum() instead of np.max()
  • Confusing method and function syntax
  • Using Python max() on NumPy arrays
3. 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))
medium
A. [3 1 2]
B. [3 7 2]
C. [5 1 9]
D. [1 2 3]

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]
Hint: 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
4. The following code throws an error. What is the problem?
import numpy as np
arr = np.array([4, 8, 6])
print(np.min(arr, axis=1))
medium
A. The array is 1D, axis=1 is invalid
B. np.min() does not accept axis argument
C. np.min() requires a list, not an array
D. The array contains non-numeric values

Solution

  1. Step 1: Check array dimensions

    The array arr is one-dimensional (shape (3,)).
  2. Step 2: Understand axis parameter

    Axis=1 means operate along columns of a 2D or higher array. For 1D arrays, axis=1 is invalid and causes an error.
  3. Final Answer:

    The array is 1D, axis=1 is invalid -> Option A
  4. Quick Check:

    1D array + axis=1 = error [OK]
Hint: Use axis only within array dimension range [OK]
Common Mistakes:
  • Using axis=1 on 1D arrays
  • Thinking np.min() can't take axis
  • Assuming array has non-numeric data
5. Given a 2D NumPy array data representing daily temperatures for a week (rows = days, columns = cities), how would you find the highest temperature recorded in each city?
hard
A. np.max(data, axis=1)
B. np.min(data, axis=1)
C. np.min(data, axis=0)
D. np.max(data, axis=0)

Solution

  1. Step 1: Understand data layout

    Rows represent days, columns represent cities. To find max per city, we want max down each column.
  2. Step 2: Use axis=0 for column-wise operation

    Using np.max(data, axis=0) finds the maximum temperature for each city across all days.
  3. Final Answer:

    np.max(data, axis=0) -> Option D
  4. Quick Check:

    Max per city = np.max(data, axis=0) [OK]
Hint: axis=0 aggregates down columns (cities) [OK]
Common Mistakes:
  • Using axis=1 to find max per city
  • Using np.min() instead of np.max()
  • Confusing rows and columns
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard