資源簡介
安裝文件:
1.python-2.7.3.msi
2.pywin32-214.win32-py2.7.exe
3.numpy-1.6.2.win32-py2.7.exe
4.matplotlib-1.1.0.win32-py2.7.exe
5.setuptools-0.6c11.win32-py2.7.exe
6.networkx-1.7rc1-py2.7.egg
代碼片段和文件信息
“““
This?module?provides?functions?to?convert?
NetworkX?graphs?to?and?from?other?formats.
The?preferred?way?of?converting?data?to?a?NetworkX?graph?
is?through?the?graph?constuctor.??The?constructor?calls
the?to_networkx_graph()?function?which?attempts?to?guess?the
input?type?and?convert?it?automatically.
Examples
--------
Create?a?10?node?random?graph?from?a?numpy?matrix
>>>?import?numpy
>>>?a=numpy.reshape(numpy.random.random_integers(01size=100)(1010))
>>>?D=nx.DiGraph(a)?
or?equivalently
>>>?D=nx.to_networkx_graph(acreate_using=nx.DiGraph())?
Create?a?graph?with?a?single?edge?from?a?dictionary?of?dictionaries
>>>?d={0:?{1:?1}}?#?dict-of-dicts?single?edge?(01)
>>>?G=nx.Graph(d)
See?Also
--------
nx_pygraphviz?nx_pydot
“““
__author__?=?“““\n“““.join([‘Aric?Hagberg?(hagberg@lanl.gov)‘
???????????????????????????‘Pieter?Swart?(swart@lanl.gov)‘
???????????????????????????‘Dan?Schult(dschult@colgate.edu)‘])
#????Copyright?(C)?2006-2011?by?
#????Aric?Hagberg?
#????Dan?Schult?
#????Pieter?Swart?
#????All?rights?reserved.
#????BSD?license.
import?warnings
import?networkx?as?nx
__all__?=?[‘to_networkx_graph‘
???????????‘from_dict_of_dicts‘?‘to_dict_of_dicts‘
???????????‘from_dict_of_lists‘?‘to_dict_of_lists‘
???????????‘from_edgelist‘?‘to_edgelist‘
???????????‘from_numpy_matrix‘?‘to_numpy_matrix‘
???????????‘to_numpy_recarray‘
???????????‘from_scipy_sparse_matrix‘?‘to_scipy_sparse_matrix‘]
def?_prep_create_using(create_using):
????“““Return?a?graph?object?ready?to?be?populated.
????If?create_using?is?None?return?the?default?(just?networkx.Graph())
????If?create_using.clear()?works?assume?it?returns?a?graph?object.
????Otherwise?raise?an?exception?because?create_using?is?not?a?networkx?graph.
????“““
????if?create_using?is?None:
????????G=nx.Graph()
????else:
????????G=create_using
????????try:
????????????G.clear()
????????except:
????????????raise?TypeError(“Input?graph?is?not?a?networkx?graph?type“)
????return?G
def?to_networkx_graph(datacreate_using=Nonemultigraph_input=False):
????“““Make?a?NetworkX?graph?from?a?known?data?structure.
????The?preferred?way?to?call?this?is?automatically
????from?the?class?constructor
????>>>?d={0:?{1:?{‘weight‘:1}}}?#?dict-of-dicts?single?edge?(01)
????>>>?G=nx.Graph(d)
????instead?of?the?equivalent
????>>>?G=nx.from_dict_of_dicts(d)
????Parameters
????----------
????data?:?a?object?to?be?converted
???????Current?known?types?are:
?????????any?NetworkX?graph
?????????dict-of-dicts
?????????dist-of-lists
?????????list?of?edges
?????????numpy?matrix
?????????numpy?ndarray
?????????scipy?sparse?matrix
?????????pygraphviz?agraph
????create_using?:?NetworkX?graph
???????Use?specified?graph?for?result.??Otherwise?a?new?graph?is?created.
????multigraph_input?:?bool?(default?False)
??????If?True?and??data?is?a?dict_of_dicts
??????try?to?create?a?multigraph?assuming?dict_of_dict_of_lists.
??????If?data?and?create_using?are?bo
評論
共有 條評論