Created
November 16, 2016 16:14
-
-
Save jovianlin/35db9997a2443379de1c10ad4db9c724 to your computer and use it in GitHub Desktop.
Bipartite Graphs in NetworkX
This file contains hidden or 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 | |
from networkx.algorithms import bipartite | |
B = nx.Graph() | |
B.add_nodes_from([1,2,3,4], bipartite=0) # Add the node attribute "bipartite" | |
B.add_nodes_from(['a', 'b', 'c', 'd'], bipartite=1) | |
B.add_edges_from([(1,'a'), (1,'b'), (2,'b'), (2,'c'), (3,'c'), (4,'a')]) | |
print 'Is connected? %s' % nx.is_connected(B) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment