Return the graph that is the projection of the bipartite graph B onto the specified nodes.
The nodes retain their names and are connected in the resulting graph if have an edge to a common node in the original graph.
Parameters : | B : NetworkX graph
nodes : list or iterable
multigraph: bool (default=False) :
|
---|---|
Returns : | Graph : NetworkX graph or multigraph
|
See also
is_bipartite, is_bipartite_node_set, sets, weighted_projected_graph, collaboration_weighted_projected_graph, overlap_weighted_projected_graph, generic_weighted_projected_graph
Notes
No attempt is made to verify that the input graph B is bipartite. Returns a simple graph that is the projection of the bipartite graph B onto the set of nodes given in list nodes. If multigraph=True then a multigraph is returned with an edge for every shared neighbor.
Directed graphs are allowed as input. The output will also then be a directed graph with edges if there is a directed path between the nodes.
The graph and node properties are (shallow) copied to the projected graph.
Examples
>>> from networkx.algorithms import bipartite
>>> B = nx.path_graph(4)
>>> G = bipartite.projected_graph(B, [1,3])
>>> print(G.nodes())
[1, 3]
>>> print(G.edges())
[(1, 3)]
If nodes , and are connected through both nodes 1 and 2 then building a multigraph results in two edges in the projection onto [,`b`]:
>>> B = nx.Graph()
>>> B.add_edges_from([('a', 1), ('b', 1), ('a', 2), ('b', 2)])
>>> G = bipartite.projected_graph(B, ['a', 'b'], multigraph=True)
>>> print(G.edges(keys=True))
[('a', 'b', 1), ('a', 'b', 2)]