def get_igraph_from_adjacency(adjacency, directed=None):
    'Get igraph graph from adjacency matrix.'
    import igraph as ig
    (sources, targets) = adjacency.nonzero()
    weights = adjacency[(sources, targets)]
    if isinstance(weights, np.matrix):
        weights = weights.A1
    g = ig.Graph(directed=directed)
    g.add_vertices(adjacency.shape[0])
    g.add_edges(list(zip(sources, targets)))
    try:
        g.es['weight'] = weights
    except:
        pass
    if (g.vcount() != adjacency.shape[0]):
        logg.warning(f'The constructed graph has only {g.vcount()} nodes. Your adjacency matrix contained redundant nodes.')
    return g
Get igraph graph from adjacency matrix.
def get_igraph_from_adjacency(adjacency, directed=None):
    
    import igraph as ig
    (sources, targets) = adjacency.nonzero()
    weights = adjacency[(sources, targets)]
    if isinstance(weights, np.matrix):
        weights = weights.A1
    g = ig.Graph(directed=directed)
    g.add_vertices(adjacency.shape[0])
    g.add_edges(list(zip(sources, targets)))
    try:
        g.es['weight'] = weights
    except:
        pass
    if (g.vcount() != adjacency.shape[0]):
        logg.warning(f'The constructed graph has only {g.vcount()} nodes. Your adjacency matrix contained redundant nodes.')
    return g