The 2D NumPy array is interpreted as an adjacency matrix for the graph.
Parameters:
A (a 2D numpy.ndarray) – An adjacency matrix representation of a graph
parallel_edges (Boolean) – If this is True, create_using is a multigraph, and A is an
integer array, then entry (i, j) in the array is interpreted as the
number of parallel edges joining vertices i and j in the graph.
If it is False, then the entries in the array are interpreted as
the weight of a single edge joining the vertices.
create_using (EasyGraph graph constructor, optional (default=eg.Graph)) – Graph type to create. If graph instance, then cleared before populated.
Notes
For directed graphs, explicitly mention create_using=eg.DiGraph,
and entry i,j of A corresponds to an edge from i to j.
If create_using is easygraph.MultiGraph or
easygraph.MultiDiGraph, parallel_edges is True, and the
entries of A are of type int, then this function returns a
multigraph (of the same type as create_using) with parallel edges.
If create_using indicates an undirected multigraph, then only the edges
indicated by the upper triangle of the array A will be added to the
graph.
If the NumPy array has a single data type for each array entry it
will be converted to an appropriate Python data type.
If the NumPy array has a user-specified compound data type the names
of the data fields will be used as attribute keys in the resulting
EasyGraph graph.
If create_using indicates a multigraph and the array has only integer
entries and parallel_edges is False, then the entries will be treated
as weights for edges joining the nodes (without creating parallel edges):
If create_using indicates a multigraph and the array has only integer
entries and parallel_edges is True, then the entries will be treated
as the number of parallel edges joining those two vertices:
Returns a graph from Pandas DataFrame containing an edge list.
The Pandas DataFrame should contain at least two columns of node names and
zero or more columns of edge attributes. Each row will be processed as one
edge instance.
Note: This function iterates over DataFrame.values, which is not
guaranteed to retain the data type across columns in the row. This is only
a problem if your row is entirely numeric and a mix of ints and floats. In
that case, all values will be returned as floats. See the
DataFrame.iterrows documentation for an example.
Parameters:
df (Pandas DataFrame) – An edge list representation of a graph
source (str or int) – A valid column name (string or integer) for the source nodes (for the
directed case).
target (str or int) – A valid column name (string or integer) for the target nodes (for the
directed case).
edge_attr (str or int, iterable, True, or None) – A valid column name (str or int) or iterable of column names that are
used to retrieve items and add them to the graph as edge attributes.
If True, all of the remaining columns will be added.
If None, no edge attributes are added to the graph.
create_using (EasyGraph graph constructor, optional (default=eg.Graph)) – Graph type to create. If graph instance, then cleared before populated.
edge_key (str or None, optional (default=None)) – A valid column name for the edge keys (for a MultiGraph). The values in
this column are used for the edge keys when adding edges if create_using
is a multigraph.
Creates a new graph from an adjacency matrix given as a SciPy sparse
matrix.
Parameters:
A (scipy sparse matrix) – An adjacency matrix representation of a graph
parallel_edges (Boolean) – If this is True, create_using is a multigraph, and A is an
integer matrix, then entry (i, j) in the matrix is interpreted as the
number of parallel edges joining vertices i and j in the graph.
If it is False, then the entries in the matrix are interpreted as
the weight of a single edge joining the vertices.
create_using (EasyGraph graph constructor, optional (default=eg.Graph)) – Graph type to create. If graph instance, then cleared before populated.
edge_attribute (string) – Name of edge attribute to store matrix numeric value. The data will
have the same type as the matrix entry (int, float, (real,imag)).
Notes
For directed graphs, explicitly mention create_using=eg.DiGraph,
and entry i,j of A corresponds to an edge from i to j.
If create_using is easygraph.MultiGraph or
easygraph.MultiDiGraph, parallel_edges is True, and the
entries of A are of type int, then this function returns a
multigraph (constructed from create_using) with parallel edges.
In this case, edge_attribute will be ignored.
If create_using indicates an undirected multigraph, then only the edges
indicated by the upper triangle of the matrix A will be added to the
graph.
Examples
>>> importscipyassp>>> importscipy.sparse# call as sp.sparse>>> A=sp.sparse.eye(2,2,1)>>> G=eg.from_scipy_sparse_matrix(A)
If create_using indicates a multigraph and the matrix has only integer
entries and parallel_edges is Falnxse, then the entries will be treated
as weights for edges joining the nodes (without creating parallel edges):
If create_using indicates a multigraph and the matrix has only integer
entries and parallel_edges is True, then the entries will be treated
as the number of parallel edges joining those two vertices:
Returns the graph adjacency matrix as a NumPy array.
Parameters:
G (graph) – The EasyGraph graph used to construct the NumPy array.
nodelist (list, optional) – The rows and columns are ordered according to the nodes in nodelist.
If nodelist is None, then the ordering is produced by G.nodes().
dtype (NumPy data type, optional) – A valid single NumPy data type used to initialize the array.
This must be a simple type such as int or numpy.float64 and
not a compound data type (see to_numpy_recarray)
If None, then the NumPy default is used.
order ({'C', 'F'}, optional) – Whether to store multidimensional data in C- or Fortran-contiguous
(row- or column-wise) order in memory. If None, then the NumPy default
is used.
multigraph_weight ({sum, min, max}, optional) – An operator that determines how weights in multigraphs are handled.
The default is to sum the weights of the multiple edges.
weight (string or None optional (default = 'weight')) – The edge attribute that holds the numerical value used for
the edge weight. If an edge does not have that attribute, then the
value 1 is used instead.
nonedge (float (default = 0.0)) – The array values corresponding to nonedges are typically set to zero.
However, this could be undesirable if there are array values
corresponding to actual edges that also have the value zero. If so,
one might prefer nonedges to have some other value, such as nan.
For directed graphs, entry i,j corresponds to an edge from i to j.
Entries in the adjacency matrix are assigned to the weight edge attribute.
When an edge does not have a weight attribute, the value of the entry is
set to the number 1. For multiple (parallel) edges, the values of the
entries are determined by the multigraph_weight parameter. The default is
to sum the weight attributes for each of the parallel edges.
When nodelist does not contain every node in G, the adjacency matrix is
built from the subgraph of G that is induced by the nodes in nodelist.
The convention used for self-loop edges in graphs is to assign the
diagonal array entry value to the weight attribute of the edge
(or the number 1 if the edge has no weight attribute). If the
alternate convention of doubling the edge weight is desired the
resulting NumPy array can be modified as follows:
Returns the graph adjacency matrix as a SciPy sparse array.
Parameters:
G (graph) – The EasyGraph graph used to construct the sparse matrix.
nodelist (list, optional) – The rows and columns are ordered according to the nodes in nodelist.
If nodelist is None, then the ordering is produced by G.nodes().
dtype (NumPy data-type, optional) – A valid NumPy dtype used to initialize the array. If None, then the
NumPy default is used.
weight (string or None optional (default='weight')) – The edge attribute that holds the numerical value used for
the edge weight. If None then all edge weights are 1.
format (str in {'bsr', 'csr', 'csc', 'coo', 'lil', 'dia', 'dok'}) – The type of the matrix to be returned (default ‘csr’). For
some algorithms different implementations of sparse matrices
can perform better. See [1]_ for details.
Returns:
A – Graph adjacency matrix.
Return type:
SciPy sparse array
Notes
For directed graphs, matrix entry i,j corresponds to an edge from i to j.
The matrix entries are populated using the edge attribute held in
parameter weight. When an edge does not have that attribute, the
value of the entry is 1.
For multiple edges the matrix values are the sums of the edge weights.
When nodelist does not contain every node in G, the adjacency matrix
is built from the subgraph of G that is induced by the nodes in
nodelist.
The convention used for self-loop edges in graphs is to assign the
diagonal matrix entry value to the weight attribute of the edge
(or the number 1 if the edge has no weight attribute). If the
alternate convention of doubling the edge weight is desired the
resulting Scipy sparse matrix can be modified as follows:
Returns the graph adjacency matrix as a SciPy sparse matrix.
Parameters:
G (graph) – The EasyGraph graph used to construct the sparse matrix.
nodelist (list, optional) – The rows and columns are ordered according to the nodes in nodelist.
If nodelist is None, then the ordering is produced by G.nodes().
dtype (NumPy data-type, optional) – A valid NumPy dtype used to initialize the array. If None, then the
NumPy default is used.
weight (string or None optional (default='weight')) – The edge attribute that holds the numerical value used for
the edge weight. If None then all edge weights are 1.
format (str in {'bsr', 'csr', 'csc', 'coo', 'lil', 'dia', 'dok'}) – The type of the matrix to be returned (default ‘csr’). For
some algorithms different implementations of sparse matrices
can perform better. See [1]_ for details.
Returns:
A – Graph adjacency matrix.
Return type:
SciPy sparse matrix
Notes
For directed graphs, matrix entry i,j corresponds to an edge from i to j.
The matrix entries are populated using the edge attribute held in
parameter weight. When an edge does not have that attribute, the
value of the entry is 1.
For multiple edges the matrix values are the sums of the edge weights.
When nodelist does not contain every node in G, the adjacency matrix
is built from the subgraph of G that is induced by the nodes in
nodelist.
The convention used for self-loop edges in graphs is to assign the
diagonal matrix entry value to the weight attribute of the edge
(or the number 1 if the edge has no weight attribute). If the
alternate convention of doubling the edge weight is desired the
resulting Scipy sparse matrix can be modified as follows: