Bird
0
0

What is wrong with this code snippet?

medium📝 Debug Q7 of 15
NumPy - Aggregation Functions
What is wrong with this code snippet?
import numpy as np
arr = np.array([1, 2, 3, 4])
print(np.average(arr, axis=1))
Aarr is not a numpy array
Bnp.average does not exist
Caxis=1 is invalid for 1D array
DMissing import statement
Step-by-Step Solution
Solution:
  1. Step 1: Check array dimensions

    arr is 1D with shape (4,), so axis=1 does not exist.
  2. Step 2: Understand axis parameter

    Axis=1 applies to 2D or higher arrays; here it causes error.
  3. Final Answer:

    axis=1 is invalid for 1D array -> Option C
  4. Quick Check:

    Axis must exist in array dimensions [OK]
Quick Trick: Use axis only if dimension exists in array shape [OK]
Common Mistakes:
  • Using axis=1 on 1D arrays
  • Thinking np.average is missing
  • Confusing array type

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More NumPy Quizzes