本文整理汇总了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)
示例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
示例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)