- 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
广告