用 SciPy 計算歐幾里得距離
與其寫多行程式碼來計算歐幾里得距離,你可以改用 SciPy。這個函式庫不只提供 euclidean 函式,還內建超過 40 種其他距離衡量方式——只要一行 import 就能使用。
本練習屬於課程
Python 中的異常偵測
練習說明
- 從對應的
scipy模組匯入euclidean函式。 - 對
M與N使用euclidean()函式。
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
# Import the euclidean function from scipy
from scipy.____.____ import euclidean
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])
# Use the euclidean function on M and N
dist_MN = ____
print(dist_MN)