Skip to content

Instantly share code, notes, and snippets.

@jovianlin
Created November 16, 2016 16:14
Show Gist options
  • Save jovianlin/35db9997a2443379de1c10ad4db9c724 to your computer and use it in GitHub Desktop.
Save jovianlin/35db9997a2443379de1c10ad4db9c724 to your computer and use it in GitHub Desktop.
Bipartite Graphs in NetworkX
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