当前位置: 首页>>代码示例>>Python>>正文


Python Graph.__init__方法代码示例

本文整理汇总了Python中networkx.classes.graph.Graph.__init__方法的典型用法代码示例。如果您正苦于以下问题:Python Graph.__init__方法的具体用法?Python Graph.__init__怎么用?Python Graph.__init__使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在networkx.classes.graph.Graph的用法示例。


在下文中一共展示了Graph.__init__方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: __init__

# 需要导入模块: from networkx.classes.graph import Graph [as 别名]
# 或者: from networkx.classes.graph.Graph import __init__ [as 别名]
    def __init__(self, data=None, **attr):
        """Initialize a graph with edges, name, or graph attributes.

        Parameters
        ----------
        data : input graph
            Data to initialize graph.  If data=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 NumPy matrix
            or 2d ndarray, a SciPy sparse matrix, 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'}

        """
        self.edge_key_dict_factory = self.edge_key_dict_factory
        Graph.__init__(self, data, **attr)
开发者ID:aparamon,项目名称:networkx,代码行数:37,代码来源:multigraph.py

示例2: __init__

# 需要导入模块: from networkx.classes.graph import Graph [as 别名]
# 或者: from networkx.classes.graph.Graph import __init__ [as 别名]
 def __init__(self,data=None,**kwds):
     Graph.__init__(self,**kwds)
     if data is not None:
         try: # build a graph
             G=Graph()
             G=convert.from_whatever(data,create_using=G)
         except:
             raise NetworkXError, "Data %s is not a tree"%data
         # check if it is a tree.
         if G.order()==G.size()+1 and \
                component.number_connected_components(G)==1:
             self.adj=G.adj.copy()
             del G
         else:
             raise NetworkXError, "Data %s is not a tree"%data
开发者ID:conerade67,项目名称:biana,代码行数:17,代码来源:tree.py

示例3: __init__

# 需要导入模块: from networkx.classes.graph import Graph [as 别名]
# 或者: from networkx.classes.graph.Graph import __init__ [as 别名]
 def __init__(self, data=None, **attr):
     self.edge_key_dict_factory = self.edge_key_dict_factory
     Graph.__init__(self, data, **attr)
开发者ID:CaptainAL,项目名称:Spyder,代码行数:5,代码来源:multigraph.py


注:本文中的networkx.classes.graph.Graph.__init__方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。