Skip to content

Instantly share code, notes, and snippets.

@RobertTalbert
Last active October 25, 2022 18:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save RobertTalbert/107c6f01b99d6a207f71ed7ec06fc12d to your computer and use it in GitHub Desktop.
Save RobertTalbert/107c6f01b99d6a207f71ed7ec06fc12d to your computer and use it in GitHub Desktop.
import networkx as nx
import matplotlib as plt
# Generate the edge list using a list comprehension that invokes the actual relation you want.
# For example, here is the relation of "divides", on the set {0,1,2,..., 20}.
# We know a divides b if b mod a = 0.
divides_edges = [(a,b) for a in range(21) for b in range(21) if b % a == 0]
divides_graph = nx.DiGraph(divides_edges)
# Here's one for "less than or equal to" on the set {0,..., 100}
less_than_equal = [(a,b) for a in range(101) for b in range(101) if a <= b]
lte_graph = nx.DiGraph(less_than_equal)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment