空间算法与数据结构 (scipy.spatial)#

空间变换#

这些包含在 scipy.spatial.transform 子模块中。

最近邻查询#

KDTree(data[, leafsize, compact_nodes, ...])

用于快速最近邻查找的 kd 树。

cKDTree(data[, leafsize, compact_nodes, ...])

用于快速最近邻查找的 kd 树

Rectangle(maxes, mins)

超矩形类。

距离度量#

距离度量包含在 scipy.spatial.distance 子模块中。

Delaunay 三角剖分、凸包和 Voronoi 图#

Delaunay(points[, furthest_site, ...])

N 维 Delaunay 细分。

ConvexHull(points[, incremental, qhull_options])

N 维凸包。

Voronoi(points[, furthest_site, ...])

N 维 Voronoi 图。

SphericalVoronoi(points[, radius, center, ...])

球面上的 Voronoi 图。

HalfspaceIntersection(halfspaces, interior_point)

N 维半空间交集。

绘图辅助函数#

delaunay_plot_2d(tri[, ax])

绘制给定 2D Delaunay 三角剖分

convex_hull_plot_2d(hull[, ax])

绘制给定 2D 凸包图

voronoi_plot_2d(vor[, ax])

绘制给定 2D Voronoi 图

另请参见

教程

单形表示#

在 Delaunay 细分(N 维单形)、凸包面和 Voronoi 脊(N-1 维单形)中出现的单形(三角形、四面体等)按以下方案表示

tess = Delaunay(points)
hull = ConvexHull(points)
voro = Voronoi(points)

# coordinates of the jth vertex of the ith simplex
tess.points[tess.simplices[i, j], :]        # tessellation element
hull.points[hull.simplices[i, j], :]        # convex hull facet
voro.vertices[voro.ridge_vertices[i, j], :] # ridge between Voronoi cells

对于 Delaunay 三角剖分和凸包,单形的邻域结构满足以下条件:tess.neighbors[i,j] 是第 i 个单形的相邻单形,与第 j 个顶点相对。如果没有邻居,则为 -1。

凸包面也定义了超平面方程

(hull.equations[i,:-1] * coord).sum() + hull.equations[i,-1] == 0

Delaunay 三角剖分中类似的超平面方程对应于相应 N+1 维抛物面上的凸包面。

Delaunay 三角剖分对象提供了一种定位包含给定点的单形以及计算重心坐标的方法。

函数#

tsearch(tri, xi)

查找包含给定点的单形。

distance_matrix(x, y[, p, threshold])

计算距离矩阵。

minkowski_distance(x, y[, p])

计算两个数组之间的 L**p 距离。

minkowski_distance_p(x, y[, p])

计算两个数组之间 L**p 距离的 p 次方。

procrustes(data1, data2)

Procrustes 分析,一种用于两个数据集的相似性测试。

geometric_slerp(start, end, t[, tol])

几何球面线性插值。

scipy.spatial 中使用的警告/错误#

QhullError

当 Qhull 遇到错误条件时引发,例如未启用解决选项时的几何简并性。