code: 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])  # this adds adjacency.shap[0] vertices
      g.add_edges(list(zip(sources, targets)))
      try:
          g.es['weight'] = weights
      except:
          pass
      if g.vcount() != adjacency.shape[0]:
          logg.warn('The constructed graph has only {} nodes. '
                    'Your adjacency matrix contained redundant nodes.'
                    .format(g.vcount()))
      return g
docs: Get igraph graph from adjacency matrix.