Last active
October 25, 2022 18:41
-
-
Save RobertTalbert/107c6f01b99d6a207f71ed7ec06fc12d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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