Bird
0
0

Identify the error in the following code snippet that applies a Gaussian filter:

medium📝 Debug Q14 of 15
SciPy - Image Processing (scipy.ndimage)
Identify the error in the following code snippet that applies a Gaussian filter:
import numpy as np
from scipy.ndimage import gaussian_filter

image = np.ones((5,5))
filtered = gaussian_filter(image, sigma='2')
print(filtered)
Agaussian_filter cannot be applied to numpy arrays
BThe array shape is invalid for gaussian_filter
CMissing import for numpy
Dsigma should be a number, not a string
Step-by-Step Solution
Solution:
  1. Step 1: Check parameter types

    The sigma parameter must be a numeric value (int or float), not a string.
  2. Step 2: Identify the cause of error

    Passing '2' as a string causes a type error when the filter tries to compute the blur.
  3. Final Answer:

    sigma should be a number, not a string -> Option D
  4. Quick Check:

    Numeric sigma required, string causes error [OK]
Quick Trick: Use numeric sigma, not string, to avoid errors [OK]
Common Mistakes:
  • Passing sigma as string
  • Assuming gaussian_filter needs special array types
  • Ignoring import errors

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More SciPy Quizzes