geometric_edges#
- geometric_edges(G, radius, p=2, *, pos_name='pos')[source]#
返回彼此之间距离在
radius
范围内的节点对的边列表。- 参数:
- GNetworkX 图
用于生成边列表的图。图
G
中的节点应具有对应于节点位置的属性pos
,该属性用于计算到其他节点的距离。- radius标量
距离阈值。如果两个节点之间的距离小于
radius
,则将边包含在边列表中。- pos_name字符串, 默认值为“pos”
表示每个节点在二维坐标中位置的节点属性名称。图中的每个节点都必须具有此属性。
- p标量, 默认值为 2
用于计算距离的 Minkowski 距离度量。默认值为 2,即欧几里德距离。
- 返回:
- edges列表
距离小于
radius
的边列表
注意
半径使用 Minkowski 距离度量
p
。如果安装了 SciPy,则使用scipy.spatial.cKDTree
来加速计算。示例
创建一个节点具有表示二维坐标的“pos”属性的图。
>>> G = nx.Graph() >>> G.add_nodes_from( ... [ ... (0, {"pos": (0, 0)}), ... (1, {"pos": (3, 0)}), ... (2, {"pos": (8, 0)}), ... ] ... ) >>> nx.geometric_edges(G, radius=1) [] >>> nx.geometric_edges(G, radius=4) [(0, 1)] >>> nx.geometric_edges(G, radius=6) [(0, 1), (1, 2)] >>> nx.geometric_edges(G, radius=9) [(0, 1), (0, 2), (1, 2)]