geometric_edges#

geometric_edges(G, radius, p)[源代码]#

返回内节点对的边列表 radius 彼此之间的关系。

参数
G网络X图

要从中生成边列表的图。中的节点 G 应该有一个属性 pos 对应于节点位置,用于计算到其他节点的距离。

radius标量

距离阈值。如果两个结点之间的距离小于 radius

p标量

这个 Minkowski distance metric 用于计算距离。

返回
edges列表

距离小于的边的列表 radius

笔记

RADIUS使用Minkowski距离度量 p 。如果Scipy可用, scipy.spatial.cKDTree 用于加快计算速度。

实例

创建一个具有节点的图形,该节点具有表示2D坐标的“pos”属性。

>>> G = nx.Graph()
>>> G.add_nodes_from([
...     (0, {"pos": (0, 0)}),
...     (1, {"pos": (3, 0)}),
...     (2, {"pos": (8, 0)}),
... ])
>>> p = 2  # Euclidean distance
>>> nx.geometric_edges(G, radius=1, p=p)
[]
>>> nx.geometric_edges(G, radius=4, p=p)
[(0, 1)]
>>> nx.geometric_edges(G, radius=6, p=p)
[(0, 1), (1, 2)]
>>> nx.geometric_edges(G, radius=9, p=p)
[(0, 1), (0, 2), (1, 2)]