Skip to content

Is there a way to find the boundary of a graph? #7326

Answered by eriknw
Linus-Foley asked this question in Q&A
Discussion options

You must be logged in to vote

These are indeed typically called boundary edges. If you know the graph is a triangular mesh, then the boundary edges are the edges that are only part of a single triangle. I know how to do this in terms of linear algebra for undirected graphs:

With scipy.sparse

a = nx.to_scipy_sparse_array(G, weight=None)
boundary_edges = (a @ a.T * a == 1).nonzero()

With python-graphblas

import graphblas as gb
from graphblas.semiring import plus_pair

A = gb.io.from_networkx(G, weight=None)
boundary_edges = plus_pair(A @ A.T).new(mask=A.S).select('==', 1).to_edgelist()
# or `.to_coo()` instead of `.to_edgelist()`

For large graphs, GraphBLAS will be much faster and use much less memory than using scipy.s…

Replies: 2 comments 1 reply

Comment options

You must be logged in to vote
1 reply
@Linus-Foley
Comment options

Answer selected by Linus-Foley
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants