Bird
0
0

What is wrong with this code?

medium📝 Debug Q7 of 15
NumPy - Aggregation Functions
What is wrong with this code?
import numpy as np
arr = np.array([[1, 2], [3, 4]])
mean_val = np.mean(arr, axis='0')
print(mean_val)
AMissing import statement for numpy
BArray must be 1D to use np.mean()
Cnp.mean() cannot be used on 2D arrays
DAxis parameter should be an integer, not a string
Step-by-Step Solution
Solution:
  1. Step 1: Check axis parameter type

    Axis must be an integer, not a string.
  2. Step 2: Identify error

    Passing '0' as string causes TypeError.
  3. Final Answer:

    Axis parameter should be an integer, not a string -> Option D
  4. Quick Check:

    Axis='0' invalid, use axis=0 [OK]
Quick Trick: Axis must be int, not string [OK]
Common Mistakes:
  • Passing axis as string instead of int
  • Assuming np.mean() only works on 1D arrays

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More NumPy Quizzes