def from_biadjacency_matrix(A, create_using=None, edge_attribute='weight'):
 G = _prep_create_using(create_using)
 (n, m) = A.shape
 G.add_nodes_from(range(n), bipartite=0)
 G.add_nodes_from(range(n, (n + m)), bipartite=1)
 triples = ((u, (n + v), d) for (u, v, d) in _generate_weighted_edges(A))
 if ((A.dtype.kind in ('i', 'u')) and G.is_multigraph()):
  chain = itertools.chain.from_iterable
  triples = chain((((u, v, 1) for d in range(w)) for (u, v, w) in triples))
 G.add_weighted_edges_from(triples, weight=edge_attribute)
 return G

def from_biadjacency_matrix ( A , create_using = None , edge_attribute = 'weight' ) : G = _prep_create_using ( create_using ) ( n , m ) = A . shape G . add_nodes_from ( range ( n ) , bipartite = 0 ) G . add_nodes_from ( range ( n , ( n + m ) ) , bipartite = 1 ) triples = ( ( u , ( n + v ) , d ) for ( u , v , d ) in _generate_weighted_edges ( A ) ) if ( ( A . dtype . kind in ( 'i' , 'u' ) ) and G . is_multigraph ( ) ) : chain = itertools . chain . from_iterable triples = chain ( ( ( ( u , v , 1 ) for d in range ( w ) ) for ( u , v , w ) in triples ) ) G . add_weighted_edges_from ( triples , weight = edge_attribute ) return G
creates a new bipartite graph from a biadjacency matrix given as a scipy sparse matrix .