Skip to main content
`Ctrl`+`K`

# Graph.__init__

Graph.__init__(incoming_graph_data=None, **attr)

  Initialize a graph with edges, name, or graph attributes.

  Parameters:
    incoming_graph_data input graph (optional, default: None)

      Data to initialize graph. If None (default) an empty graph is created. The data can be an edge list, or any NetworkX graph object. If the corresponding optional Python packages are installed the data can also be a 2D NumPy array, a SciPy sparse array, or a PyGraphviz graph.

    attr keyword arguments, optional (default= no attributes)

      Attributes to add to graph as key=value pairs.

  See also

  `convert`

  Examples

      >>> G = nx.Graph()  # or DiGraph, MultiGraph, MultiDiGraph, etc
      >>> G = nx.Graph(name="my graph")
      >>> e = [(1, 2), (2, 3), (3, 4)]  # list of edges
      >>> G = nx.Graph(e)

  Arbitrary graph attribute pairs (key=value) may be assigned

      >>> G = nx.Graph(e, day="Friday")
      >>> G.graph
      {'day': 'Friday'}