LoslegenKostenlos loslegen

Finding the euclidean distance manually

Euclidean distance is the most popular distance metric in statistics. Its popularity mainly comes from the fact that it is intuitive to understand. It is the Pythagorean theorem applied in Cartesian coordinates.

Practice calculating it with NumPy manually, which is already loaded under its standard alias np.

Diese Übung ist Teil des Kurses

Anomaly Detection in Python

Kurs anzeigen

Anleitung zur Übung

  • Subtract M from N (or vice versa), square the results, and save them into squared_diffs.
  • Calculate the sum of the differences into sum_diffs.
  • Find the square root of the sum to find the final distance—dist_MN.

Interaktive Übung

Vervollständige den Beispielcode, um diese Übung erfolgreich abzuschließen.

M = np.array([14, 17, 18, 20, 14, 12, 19, 13, 17, 20])
N = np.array([63, 74, 76, 72, 64, 75, 75, 61, 50, 53])

# Subtract M from N and square the result
squared_diffs = ____

# Calculate the sum
sum_diffs = ____

# Find the square root
dist_MN = ____

print(dist_MN)
Code bearbeiten und ausführen