Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add default value p=2 for minkowski distance metric. #5700

Merged
merged 1 commit into from
Jun 7, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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