Skip to content

Commit

Permalink
Add default value p=2 for minkowski distance metric. (#5700)
Browse files Browse the repository at this point in the history
  • Loading branch information
rossbar committed Jun 7, 2022
1 parent 52fe066 commit ad99a58
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions networkx/generators/geometric.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def euclidean(x, y):
return math.dist(x, y)


def geometric_edges(G, radius, p):
def geometric_edges(G, radius, p=2):
"""Returns edge list of node pairs within `radius` of each other.
Parameters
Expand All @@ -49,10 +49,10 @@ def geometric_edges(G, radius, p):
radius : scalar
The distance threshold. Edges are included in the edge list if the
distance between the two nodes is less than `radius`.
p : scalar
p : scalar, default=2
The `Minkowski distance metric
<https://en.wikipedia.org/wiki/Minkowski_distance>`_ use to compute
distances.
<https://en.wikipedia.org/wiki/Minkowski_distance>`_ used to compute
distances. The default value is 2, i.e. Euclidean distance.
Returns
-------
Expand All @@ -75,14 +75,13 @@ def geometric_edges(G, radius, p):
... (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=1)
[]
>>> nx.geometric_edges(G, radius=4, p=p)
>>> nx.geometric_edges(G, radius=4)
[(0, 1)]
>>> nx.geometric_edges(G, radius=6, p=p)
>>> nx.geometric_edges(G, radius=6)
[(0, 1), (1, 2)]
>>> nx.geometric_edges(G, radius=9, p=p)
>>> nx.geometric_edges(G, radius=9)
[(0, 1), (0, 2), (1, 2)]
"""
nodes_pos = G.nodes(data="pos")
Expand Down

0 comments on commit ad99a58

Please sign in to comment.