Home | Trees | Indices | Help |
---|
|
Convert NetworkX graphs to and from other formats.
from_whatever attemps to guess the input format
Create a 10 node random digraph
>>> from networkx import * >>> import numpy >>> a=numpy.reshape(numpy.random.random_integers(0,1,size=100),(10,10)) >>> D=from_whatever(a,create_using=DiGraph()) # or D=DiGraph(a)
For graphviz formats see networkx.drawing.nx_pygraphviz or networkx.drawing.nx_pydot.
$Id: convert.py 701 2007-11-08 05:08:53Z aric $
Author: Aric Hagberg (hagberg@lanl.gov)
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|
Returns 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. |
Attempt to make a NetworkX graph from an known type. Current known types are: any NetworkX graph dict-of-dicts dist-of-lists numpy matrix numpy ndarray scipy sparse matrix pygraphviz agraph |
Return graph G as a Python dict of lists. If nodelist is defined return a dict of lists with only those nodes. Completely ignores edge data for XGraph and XDiGraph. |
Return graph G as a Python dictionary of dictionaries. If nodelist is defined return a dict of dicts with only those nodes. If edge_data is given, the value of the dictionary will be set to edge_data for all edges. This is useful to make an adjacency matrix type representation with 1 as the edge data. |
Return a NetworkX graph G from a Python dictionary of dictionaries. The value of the inner dict becomes the edge_data for the NetworkX graph EVEN if create_using is a NetworkX Graph which doesn't ever use this data. If create_using is an XGraph/XDiGraph with multiedges==True, the edge_data should be a list, though this routine does not check for that. |
Return adjacency matrix of graph as a numpy matrix. If nodelist is defined return adjacency matrix with nodes in nodelist in the order specified. If not the ordering is whatever order the method G.nodes() produces. For Graph/DiGraph types which have no edge data The value of the entry A[u,v] is one if there is an edge u-v and zero otherwise. For XGraph/XDiGraph the edge data is assumed to be a weight and be able to be converted to a valid numpy type (e.g. an int or a float). The value of the entry A[u,v] is the weight given by get_edge(u,v) one if there is an edge u-v and zero otherwise. Graphs with multi-edges are not handled. |
Return adjacency matrix of graph as a scipy sparse matrix. Uses lil_matrix format. To convert to other formats see scipy.sparse documentation. If nodelist is defined return adjacency matrix with nodes in nodelist in the order specified. If not the ordering is whatever order the method G.nodes() produces. For Graph/DiGraph types which have no edge data The value of the entry A[u,v] is one if there is an edge u-v and zero otherwise. For XGraph/XDiGraph the edge data is assumed to be a weight and be able to be converted to a valid numpy type (e.g. an int or a float). The value of the entry A[u,v] is the weight given by get_edge(u,v) one if there is an edge u-v and zero otherwise. Graphs with multi-edges are not handled. >>> A=scipy_sparse_matrix(G) >>> A.tocsr() # convert to compressed row storage |
Home | Trees | Indices | Help |
---|
Generated by Epydoc 3.0beta1 on Sun Aug 17 12:04:43 2008 | http://epydoc.sourceforge.net |