- SciPy 教程
- SciPy - 主頁
- SciPy - 簡介
- SciPy - 配置環境
- SciPy - 基本功能
- SciPy - 群集
- SciPy - 常量
- SciPy - FFTpack
- SciPy - 整合
- SciPy - 插值
- SciPy - 輸入和輸出
- SciPy - 線性代數
- SciPy - Ndimage
- SciPy - 最佳化
- SciPy - 統計
- SciPy - CSGraph
- SciPy - 空間
- SciPy - ODR
- SciPy - 特殊包
- SciPy 有用資源
- SciPy - 參考
- SciPy - 快速指南
- SciPy - 有用資源
- SciPy - 討論
SciPy - maxinconsts() 方法
SciPy maxinconsts() 方法用於計算兩個資料集之間的距離。我們通常在計算矩陣問題時使用此函式。
透過使用此方法,我們可以瞭解豪斯多夫距離 [directed_hausdorff()] 並瞭解如何用程式設計方法解決此問題。豪斯多夫距離的常見用途是找到兩個點集之間的距離計算。
語法
以下是 SciPy maxinconsts() 方法的語法 −
maxinconsts(Z, R) or, directed_hausdorff(x, y)
引數
此方法接受兩個引數 −
- Z:此引數用於儲存給定矩陣的中位數資料。
- R:此引數儲存名為 inconsistent() 的內建函式,該函式將給定矩陣轉換為不一致矩陣。
- x、y:這兩個引數都基於相同或不同的矩陣工作。
返回值
此方法返回浮點值型別的結果。
示例 1
以下是顯示 SciPy maxinconsts() 方法使用方法的基本示例。
from scipy.cluster.hierarchy import median, inconsistent, maxinconsts
from scipy.spatial.distance import pdist
X = [[0, 0], [0, 1], [1, 0],
[0, 4], [0, 3], [1, 4],
[4, 0], [3, 0], [4, 1],
[4, 4], [3, 4], [4, 3]]
Z = median(pdist(X))
R = inconsistent(Z)
res = maxinconsts(Z, R)
print(res)
輸出
上述程式碼生成以下輸出 −
[0. 0. 0. 0. 0.70710678 0.70710678 0.70710678 0.70710678 1.15470054 1.15470054 1.15470054]
示例 2
程式下方演示瞭如何使用兩個不同陣列的豪斯多夫距離。
import numpy as np
from scipy.spatial.distance import directed_hausdorff
x = np.array([[0, 0], [1, 1], [2, 2], [3, 3]])
y = np.array([[0, 1], [1, 2]])
dist, index_x, index_y = directed_hausdorff(x, y)
print("Directed Hausdorff Distance:", dist)
print("Index in x:", index_x)
print("Index in y:", index_y)
輸出
上述程式碼生成以下輸出 −
Directed Hausdorff Distance: 2.23606797749979 Index in x: 3 Index in y: 1
scipy_reference.htm
廣告