Bird
0
0

Find the error in this code snippet:

medium📝 Debug Q7 of 15
SciPy - Statistical Tests

Find the error in this code snippet:

import numpy as np
from scipy.stats import chi2_contingency

observed = np.array([[5, 10], [15]])
chi2, p, dof, expected = chi2_contingency(observed)
print(chi2)
ANo error, code runs correctly
Bchi2_contingency does not return four values
CImport statement is missing parentheses
DObserved array rows have unequal lengths causing an error
Step-by-Step Solution
Solution:
  1. Step 1: Check shape of observed array

    The second row has only one element, causing a ragged array error.
  2. Step 2: Understand NumPy array requirements

    NumPy arrays must have equal-length rows; ragged arrays cause errors.
  3. Final Answer:

    Observed array rows have unequal lengths causing an error -> Option D
  4. Quick Check:

    NumPy arrays require equal-length rows [OK]
Quick Trick: All rows in NumPy arrays must be same length [OK]
Common Mistakes:
MISTAKES
  • Ignoring ragged array error
  • Assuming chi2_contingency returns different values
  • Misreading import syntax

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More SciPy Quizzes