Bird
0
0

Identify the mistake in this code:

medium📝 Debug Q7 of 15
NumPy - Aggregation Functions
Identify the mistake in this code:
import numpy as np
arr = np.array([1, 2, 3, 4, 5])
variance = np.var(arr, ddof=1)
print(variance)
AMissing import statement
Bnp.var() does not accept ddof parameter
Cddof=1 calculates sample variance, not population variance
DVariance cannot be calculated on integer arrays
Step-by-Step Solution
Solution:
  1. Step 1: Understand ddof parameter

    ddof=1 changes divisor to N-1, calculating sample variance.
  2. Step 2: Check if this is a mistake

    If population variance is intended, ddof should be 0 or omitted.
  3. Final Answer:

    ddof=1 calculates sample variance, not population variance -> Option C
  4. Quick Check:

    ddof=1 means sample variance [OK]
Quick Trick: ddof=1 means sample variance, ddof=0 means population [OK]
Common Mistakes:
  • Confusing sample and population variance
  • Thinking ddof is invalid
  • Ignoring ddof effect

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More NumPy Quizzes