Bird
0
0

The following code throws an error. What is the problem?

medium📝 Debug Q14 of 15
NumPy - Aggregation Functions
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))
AThe array is 1D, axis=1 is invalid
Bnp.min() does not accept axis argument
Cnp.min() requires a list, not an array
DThe array contains non-numeric values
Step-by-Step Solution
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]
Quick Trick: 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

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More NumPy Quizzes