def from_scipy_sparse_matrix(A, parallel_edges=False, create_using=None, edge_attribute='weight'):
 G = _prep_create_using(create_using)
 (n, m) = A.shape
 if (n != m):
  raise nx.NetworkXError(('Adjacency matrix is not square. nx,ny=%s' % (A.shape,)))
 G.add_nodes_from(range(n))
 triples = _generate_weighted_edges(A)
 if ((A.dtype.kind in ('i', 'u')) and G.is_multigraph() and parallel_edges):
  chain = itertools.chain.from_iterable
  triples = chain((((u, v, 1) for d in range(w)) for (u, v, w) in triples))
 if (G.is_multigraph() and (not G.is_directed())):
  triples = ((u, v, d) for (u, v, d) in triples if (u <= v))
 G.add_weighted_edges_from(triples, weight=edge_attribute)
 return G

def from_scipy_sparse_matrix ( A , parallel_edges = False , create_using = None , edge_attribute = 'weight' ) : G = _prep_create_using ( create_using ) ( n , m ) = A . shape if ( n != m ) : raise nx . NetworkXError ( ( 'Adjacency matrix is not square. nx,ny=%s' % ( A . shape , ) ) ) G . add_nodes_from ( range ( n ) ) triples = _generate_weighted_edges ( A ) if ( ( A . dtype . kind in ( 'i' , 'u' ) ) and G . is_multigraph ( ) and parallel_edges ) : chain = itertools . chain . from_iterable triples = chain ( ( ( ( u , v , 1 ) for d in range ( w ) ) for ( u , v , w ) in triples ) ) if ( G . is_multigraph ( ) and ( not G . is_directed ( ) ) ) : triples = ( ( u , v , d ) for ( u , v , d ) in triples if ( u <= v ) ) G . add_weighted_edges_from ( triples , weight = edge_attribute ) return G
creates a new graph from an adjacency matrix given as a scipy sparse matrix .