空間演算法與資料結構 (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