Bird
0
0

Given the following code:

medium📝 Predict Output Q5 of 15
SciPy - Clustering and Distance
Given the following code:
from scipy.cluster.hierarchy import linkage
import numpy as np
X = np.array([[1, 2], [3, 4], [5, 6]])
Z = linkage(X, method='complete')
print(Z.shape)

What will be printed?
A(3, 3)
B(2, 4)
C(2, 3)
D(3, 4)
Step-by-Step Solution
Solution:
  1. Step 1: Determine number of samples in X

    X has 3 samples (rows).
  2. Step 2: Calculate linkage output shape

    Output shape is (n-1, 4) = (2, 4).
  3. Final Answer:

    (2, 4) -> Option B
  4. Quick Check:

    linkage output shape for 3 samples = (2, 4) [OK]
Quick Trick: Linkage output rows = samples - 1 [OK]
Common Mistakes:
  • Confusing number of samples with output rows
  • Miscounting columns in output
  • Assuming output shape equals input shape

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More SciPy Quizzes