Bird
0
0

What is the issue with this code snippet?

medium📝 Debug Q6 of 15
SciPy - Clustering and Distance
What is the issue with this code snippet?
from scipy.cluster.hierarchy import linkage
X = [[1, 2], [3, 4], [5, 6]]
Z = linkage(method='complete', X)
AThe positional argument <code>X</code> should come before the keyword argument <code>method</code>.
BThe method 'complete' is not a valid linkage method.
CThe input data <code>X</code> must be a NumPy array, not a list.
DThe linkage function requires a distance matrix, not raw data.
Step-by-Step Solution
Solution:
  1. Step 1: Check argument order

    In Python, positional arguments must come before keyword arguments.
  2. Step 2: Identify error in call

    The code passes method='complete' first, then X as positional, which is invalid syntax.
  3. Step 3: Validate other options

    'complete' is a valid method, lists are accepted as input, and raw data is allowed.
  4. Final Answer:

    The positional argument X should come before the keyword argument method. -> Option A
  5. Quick Check:

    Positional args before keywords [OK]
Quick Trick: Positional arguments must precede keyword arguments [OK]
Common Mistakes:
  • Passing keyword arguments before positional
  • Assuming lists are invalid input
  • Confusing linkage input requirements

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More SciPy Quizzes