Skip to content
CampusEduX

Problem 2: Calculate Pairwise Distances

Easypython
Learn the Concept: Clustering

Problem Description

Write a Python program that calculates the Euclidean distance between every pair of points in a small dataset, storing the results in a distance matrix.

Input

A small list of 2D points.

Output

A distance matrix showing pairwise distances between all points.

Constraints

  • At least 4 points.

Example Input

text
[[1,1],[2,2],[8,8]]

Example Output

text
(A 3x3 matrix showing distances between each pair of the 3 points)

Concepts Covered

Euclidean distance formula, nested loops or scipy.spatial.distance.

Related Problems

  • Problem 1: Visualize Unlabeled Data
    Easy · python
    Solve Problem
  • Problem 3: Manually Group Points by a Distance Threshold
    Easy · python
    Solve Problem
  • Problem 4: Scale Data Before Clustering
    Easy · python
    Solve Problem

Input (stdin)

Output

Run your code to see output here...