Bird
0
0

Given the code below, what will dist_matrix.shape output?

medium📝 Predict Output Q5 of 15
SciPy - Clustering and Distance
Given the code below, what will dist_matrix.shape output?
import numpy as np
from scipy.spatial import distance_matrix
X = np.array([[1, 2], [3, 4], [5, 6]])
dist_matrix = distance_matrix(X, X)
A(2, 2)
B(3, 3)
C(3, 2)
D(2, 3)
Step-by-Step Solution
Solution:
  1. Step 1: Understand input arrays

    Both inputs are the same array with 3 points, each with 2 coordinates.
  2. Step 2: Determine output shape of distance matrix

    Distance matrix shape is (number of points in first array, number in second), here (3, 3).
  3. Final Answer:

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

    Distance matrix shape = (len(X), len(X)) = (3, 3) [OK]
Quick Trick: Distance matrix shape = (len(first array), len(second array)) [OK]
Common Mistakes:
  • Confusing coordinate dimension with number of points
  • Assuming shape depends on coordinate count
  • Mixing up rows and columns

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More SciPy Quizzes