Bird
0
0

What is wrong with this code?

medium📝 Debug Q7 of 15
SciPy - Image Processing (scipy.ndimage)
What is wrong with this code?
import numpy as np
from scipy.ndimage import gaussian_filter

img = np.array([[1, 2], [3, 4]])
result = gaussian_filter(img, sigma=1, mode='invalid')
print(result)
Aimg must be 3D array
Bsigma must be greater than 1
Cmode='invalid' is not a valid mode option
Dgaussian_filter requires kernel size parameter
Step-by-Step Solution
Solution:
  1. Step 1: Check mode parameter validity

    The mode parameter controls how borders are handled. Valid options include 'reflect', 'constant', 'nearest', 'mirror', 'wrap'. 'invalid' is not valid and will cause an error.
  2. Step 2: Verify other parameters

    Sigma can be any positive number. The input can be 2D. Kernel size is inferred from sigma.
  3. Final Answer:

    mode='invalid' is not a valid mode option -> Option C
  4. Quick Check:

    Invalid mode parameter = C [OK]
Quick Trick: Use valid mode strings like 'reflect' or 'constant' [OK]
Common Mistakes:
  • Using invalid mode strings
  • Thinking sigma must be >1
  • Assuming input must be 3D

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More SciPy Quizzes