Bird
0
0

Identify the error in this code snippet:

medium📝 Debug Q14 of 15
SciPy - Clustering and Distance
Identify the error in this code snippet:
import numpy as np
from scipy.spatial import distance_matrix
points = np.array([[0, 0], [1, 1]])
dm = distance_matrix(points)
print(dm)
Adistance_matrix cannot handle integer arrays
Bdistance_matrix requires two arguments, but only one is given
Cnumpy array must be 1D, but points is 2D
Dprint statement syntax is incorrect
Step-by-Step Solution
Solution:
  1. Step 1: Check function parameters

    distance_matrix needs two arrays of points to compute distances between them.
  2. Step 2: Identify missing argument

    Only one argument points is passed, so it will raise a TypeError.
  3. Final Answer:

    distance_matrix requires two arguments, but only one is given -> Option B
  4. Quick Check:

    Missing second argument error [OK]
Quick Trick: distance_matrix needs two point sets as input [OK]
Common Mistakes:
  • Passing only one array instead of two
  • Assuming it computes distances within one set automatically
  • Ignoring function signature requirements

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More SciPy Quizzes