本文整理匯總了Python中networkx.from_dict_of_dicts方法的典型用法代碼示例。如果您正苦於以下問題:Python networkx.from_dict_of_dicts方法的具體用法?Python networkx.from_dict_of_dicts怎麽用?Python networkx.from_dict_of_dicts使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類networkx
的用法示例。
在下文中一共展示了networkx.from_dict_of_dicts方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: graph_from_dict
# 需要導入模塊: import networkx [as 別名]
# 或者: from networkx import from_dict_of_dicts [as 別名]
def graph_from_dict(graph_dict):
if 'graph_type' not in graph_dict:
raise ValueError('graph_dict must contain key "graph_type"')
# todo: use type() instead of this mess
if graph_dict['graph_type'] == 'MultiDiGraph':
return multi_digraph_from_dict(graph_dict['graph_dict'])
elif graph_dict['graph_type'] == 'MultiGraph':
return nx.from_dict_of_dicts(graph_dict['graph_dict'], multigraph_input=True)
elif graph_dict['graph_type'] == 'DiGraph':
return nx.from_dict_of_dicts(graph_dict['graph_dict'])
elif graph_dict['graph_type'] == 'Graph':
return nx.from_dict_of_dicts(graph_dict['graph_dict'])
elif graph_dict['graph_type'] == 'other':
return nx.from_dict_of_dicts(graph_dict['graph_dict'])
else:
raise ValueError("the value for 'graph_type' in graph_dict is not of the accepted values.")